# 2015--2018 Wesley Willett, Petra Isenberg and Lonni Besancon, Anastasia Bezerianos # Bar Chart depicting CIs library(ggplot2) library(reshape2) barChart <- function(resultTable, techniques, nbTechs = -1, ymin, ymax, xAxisLabel = "I am the X axis", yAxisLabel = "I am the Y Label",annotation="", color_c="black"){ #tr <- t(resultTable) if(nbTechs <= 0){ stop('Please give a positive number of Techniques, nbTechs'); } tr <- as.data.frame(resultTable) nbTechs <- nbTechs - 1 ; # seq will generate nb+1 #now need to calculate one number for the width of the interval tr$CI2 <- tr$upperBound_CI - tr$mean_time tr$CI1 <- tr$mean_time - tr$lowerBound_CI #add a technique column tr$technique <- factor(seq.int(0, nbTechs, 1)); breaks <- c(as.character(tr$technique)); print(tr) g <- ggplot(tr, aes(x=technique, y=mean_time)) + # geom_bar(stat="identity",fill = I("#CCCCCC")) + geom_errorbar(aes(ymin=mean_time-CI1, ymax=mean_time+CI2), width=0, # Width of the error bars size = 1.1, color=color_c ) + #labs(title="Overall time per technique") + labs(x = xAxisLabel, y = yAxisLabel) + scale_y_continuous(limits = c(ymin,ymax)) + scale_x_discrete(name="",breaks,techniques,position = "top")+ coord_flip() + theme(panel.background = element_rect(fill = 'white', colour = 'white'), #axis.title=element_text(size = rel(1.2), colour = "black"), axis.title = element_blank(), axis.text=element_text(size = rel(1.6), colour = "black"), axis.text.y = element_text(hjust=1), panel.grid.major = element_line(colour = "#DDDDDD"), panel.grid.major.y = element_blank(), axis.ticks = element_blank(), panel.grid.minor.y = element_blank())+ geom_point(size=2, colour=color_c)+ # dots #geom_label(aes(x = nbTechs+0.5, y = ymax, label = annotation), label.size = 0, label.padding= unit(0.2, "lines"), nudge_x = 0.3, colour = "white", fill = "#CCCCCC",size = rel(8)) # dots geom_label(aes(y=0,x=nbTechs+1.4, label = annotation),hjust=0.5,label.padding= unit(0.4, "lines"), vjust = 0.5, nudge_x = 0.5, nudge_y = ymin +(0.08*(ymax-ymin)), label.size = 0, colour = "white", fill = "#aaaaaa", inherit.aes=FALSE, alpha=.8, size=rel(5)) #annotate("text",Inf,Inf,label=annotation,hjust=1,vjust=1,size = rel(6)) print(g) } barChart_corr <- function(resultTable, techniques, nbTechs = -1, ymin, ymax, xAxisLabel = "I am the X axis", yAxisLabel = "I am the Y Label",annotation=""){ if(nbTechs <= 0){ stop('Please give a positive number of Techniques, nbTechs'); } tr <- as.data.frame(resultTable) nbTechs <- nbTechs - 1 ; # seq will generate nb+1 #now need to calculate one number for the width of the interval tr$CI2 <- tr$upperBound_CI - tr$mean_time tr$CI1 <- tr$mean_time - tr$lowerBound_CI tr$CI2_corr <- tr$upperBound_CI_corr - tr$mean_time tr$CI1_corr <- tr$mean_time - tr$lowerBound_CI_corr #add a technique column tr$technique <- factor(seq.int(0, nbTechs, 1)); breaks <- c(as.character(tr$technique)); print(tr) g <- ggplot(tr, aes(x=technique, y=mean_time)) + # geom_bar(stat="identity",fill = I("#CCCCCC")) + geom_errorbar(aes(ymin=mean_time-CI1_corr, ymax=mean_time+CI2_corr), width=0.1, # Width of the error bars size = 0.5, color = "red" ) + geom_errorbar(aes(ymin=mean_time-CI1, ymax=mean_time+CI2), width=0, # Width of the error bars size = 1.1 ) + #labs(title="Overall time per technique") + labs(x = xAxisLabel, y = yAxisLabel) + scale_y_continuous(limits = c(ymin,ymax)) + scale_x_discrete(name="",breaks,techniques,position = "top")+ coord_flip() + theme(panel.background = element_rect(fill = 'white', colour = 'white'), #axis.title=element_text(size = rel(1.2), colour = "black"), axis.title = element_blank(), axis.text=element_text(size = rel(1.8), colour = "black"), axis.text.y = element_text(hjust=1), panel.grid.major = element_line(colour = "#DDDDDD"), panel.grid.major.y = element_blank(), axis.ticks = element_blank(), panel.grid.minor.y = element_blank())+ geom_point(size=2, colour="black")+ # dots #geom_label(aes(x = nbTechs+0.5, y = ymax, label = annotation), label.size = 0, label.padding= unit(0.2, "lines"), nudge_x = 0.3, colour = "white", fill = "#CCCCCC",size = rel(10),alpha=0.5) # dots geom_label(aes(y=0,x=nbTechs+1.18, label = annotation),hjust=0.5,label.padding= unit(0.4, "lines"), vjust = 0.5, nudge_y = ymin+(0.025*(ymax-ymin)), label.size = 0, colour = "white", fill = "#aaaaaa", inherit.aes=FALSE, alpha=.8,size=rel(8)) print(g) }