|
| 1 | +#!/usr/bin/env Rscript |
| 2 | +library(ggplot2); |
| 3 | +library(plyr); |
| 4 | + |
| 5 | +# get __dirname and load ./_cli.R |
| 6 | +args = commandArgs(trailingOnly = F); |
| 7 | +dirname = dirname(sub("--file=", "", args[grep("--file", args)])); |
| 8 | +source(paste0(dirname, '/_cli.R'), chdir=T); |
| 9 | + |
| 10 | +if (!is.null(args.options$help) || |
| 11 | + (!is.null(args.options$plot) && args.options$plot == TRUE)) { |
| 12 | + stop("usage: cat file.csv | Rscript bar.R |
| 13 | + --help show this message |
| 14 | + --plot filename save plot to filename"); |
| 15 | +} |
| 16 | + |
| 17 | +plot.filename = args.options$plot; |
| 18 | + |
| 19 | +dat = read.csv( |
| 20 | + file('stdin'), |
| 21 | + colClasses=c('character', 'character', 'character', 'numeric', 'numeric') |
| 22 | +); |
| 23 | +dat = data.frame(dat); |
| 24 | + |
| 25 | +dat$nameTwoLines = paste0(dat$filename, '\n', dat$configuration); |
| 26 | +dat$name = paste0(dat$filename, ' ', dat$configuration); |
| 27 | + |
| 28 | +# Create a box plot |
| 29 | +if (!is.null(plot.filename)) { |
| 30 | + p = ggplot(data=dat, aes(x=nameTwoLines, y=rate, fill=binary)); |
| 31 | + p = p + geom_bar(stat="summary", position=position_dodge()); |
| 32 | + p = p + ylab("rate of operations (higher is better)"); |
| 33 | + p = p + xlab("benchmark"); |
| 34 | + p = p + theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)); |
| 35 | + ggsave(plot.filename, p); |
| 36 | +} |
0 commit comments