I'm using R to generate some plots of some metrics and getting nice results like this for data that has > 3 data points:
However, I'm noticing that for data with only a few values - I get very poor results.
If I draw a plot with only two data points, I get a blank plot.
foo_two_points.dat
cluster,account,current_database,action,operation,count,day
cluster19,col0063,col0063,foo_two,two_bar,10,2016-10-04 00:00:00-07:00
cluster61,dwm4944,dwm4944,foo_two,two_bar,2,2016-12-14 00:00:00-08:00
If I draw one data point, it works.
foo_one_point.dat
cluster,account,current_database,action,operation,count,day
cluster1,foo0424,foo0424,fooone,,2,2016-11-01 00:00:00-07:00
Three, it almost works, but isn't accurate.
foo_three_points.dat
cluster,account,current_database,action,operation,count,day
cluster23,col2225,col2225,foo_three,bar,9,2016-12-22 00:00:00-08:00
cluster23,col2225,col2225,foo_three,bar,1,2016-12-29 00:00:00-08:00
cluster12,red1782,red1782,foo_three,bar,2,2016-10-25 00:00:00-07:00
But two or three points - nope.
Here is my plot.r file:
library(ggplot2)
library(scales)
args<-commandArgs(TRUE)
filename<-args[1]
n = nchar(filename) - 4
thetitle = substring(filename, 1, n)
print(thetitle)
png_filename <- stringi::stri_flatten(stringi::stri_join(c(thetitle,'.png')))
wide<-as.numeric(args[2])
high<-as.numeric(args[3])
legend_left<-as.numeric(args[4])
pos <- if(legend_left == 1) c(1,0) else c(0,1)
place <- if(legend_left == 1) 'left' else 'right'
print(wide)
print(high)
print(filename)
print(png_filename)
dat = read.csv(filename)
dat$account = as.character(dat$account)
dat$action=as.character(dat$action)
dat$operation = as.character(dat$operation)
dat$count = as.integer(dat$count)
dat$day = as.Date(dat$day)
dat[is.na(dat)]<-"N/A"
png(png_filename,width=wide,height=high)
p <- ggplot(dat, aes(x=day, y=count, fill=account, labels=TRUE))
p <- p + geom_histogram(stat="identity")
p <- p + scale_x_date(labels=date_format("%b-%Y"), limits=as.Date(c('2016-10-01','2017-01-01')))
p <- p + theme(legend.position="bottom")
p <- p + guides(fill=guide_legend(nrow=5, byrow=TRUE))
p <- p + theme(text = element_text(size=15))
p<-p+labs(title=thetitle)
print(p)
dev.off()
Here's the command I use to run it:
RScript plot.r foo_five_points.dat 1600 800 0
What am I doing wrong?