this is for holding javascript data
Brandon Holt R scripts experimenting with plotting
over 9 years ago
Commit id: 85025c85ad8c347496b4750f678505e8df3d3077
deletions | additions
diff --git a/.gitignore b/.gitignore
index 62c472e..d6e4577 100644
--- a/.gitignore
+++ b/.gitignore
...
.ipynb_checkpoints
data/*.pdf
diff --git a/data/common.R b/data/common.R
new file mode 100644
index 0000000..baeef63
--- /dev/null
+++ b/data/common.R
...
suppressPackageStartupMessages(require(RMySQL))
suppressPackageStartupMessages(require(sqldf))
suppressPackageStartupMessages(require(ggplot2))
options(RMySQL.dbname="claret") # (rest comes from $HOME/.my.cnf)
db <- function(query, factors=c(), numeric=c()) {
d <- sqldf(query)
d[factors] <- lapply(d[factors], factor)
d[numeric] <- lapply(d[numeric], as.numeric)
return(d)
}
as.continuous <- function(var) as.numeric(as.character(var))
save <- function(g, file=sprintf("%s/%s.pdf",FILE_DIR,FILE_BASE), w=3.3, h=3.1) {
ggsave(plot=g, filename=file, width=w, height=h)
print(sprintf("saved: %s", file))
}
prettify <- function(str) gsub('_',' ',gsub('([a-z])([a-z]+)',"\\U\\1\\E\\2",str,perl=TRUE))
regex_match <- function(reg,str) length(grep(reg,str)) > 0
label_pretty <- function(variable, value) {
vname <- if (regex_match('variable|value',variable)) '' else sprintf('%s:', variable)
lapply(paste(vname, prettify(as.character(value))), paste, collapse="\n")
}
geom_mean <- function(geom) stat_summary(fun.y='mean', geom=geom, labeller=label_pretty)
geom_meanbar <- function(labeller=label_pretty) {
return(list(
stat_summary(fun.y=mean, geom='bar'),
stat_summary(fun.data=mean_cl_normal, geom='errorbar', width=0.2)
))
}
theme_mine <- theme_bw()
diff --git a/data/plot.R b/data/plot.R
new file mode 100644
index 0000000..05fe1b1
--- /dev/null
+++ b/data/plot.R
...
#!/usr/bin/env Rscript
source('common.R')
d <- db('select * from tapir',
factors=c('nshards'),
numeric=c('total_time', 'txn_count'))
d$txn_abort_rate <- d$txn_failed / d$txn_count + d$txn_failed
d$throughput <- d$txn_count * d$nclients / d$total_time
common_layers <- list(theme_mine
, facet_grid(nshards~., labeller=label_pretty)
)
save(ggplot(d, aes(
x = nclients,
y = throughput,
fill = nshards,
group = nshards,
# color = nshards
))+
geom_meanbar()+
common_layers
)