I am trying to customize boxplot, and I was pretty successful except one point. The point that I cannot understand is how I can use stat_summary to show outliers. I have different box plots in one big plot and the outliers do not show on the output. However, if I modify my data and only fed the R with one type of data(only for single box plot) my code works fine and I can see the ourliers crystal clear in the output. I appreciate any help.
Many thanks,
f <- function(x) {r <- c( quantile(x,probs=c(0.25))-(1.5*(quantile(x,probs=c(0.75))-quantile(x,probs=c(0.25)))) ,quantile(x, probs = c(0.25)), quantile(x, probs = c(0.5)), quantile(x, probs = c(0.75)), quantile(x,probs=c(0.75))+(1.5*(quantile(x,probs=c(0.75))-quantile(x,probs=c(0.25)))) );names(r) <- c('ymin', 'lower', 'middle', 'upper', 'ymax'); r}
o <-function(x) { print(x); if (length(x) > 7) { pp = subset(x, x < (quantile(x, probs = c(0.25)) - (1.5 * (quantile(x, probs = c(0.75)) - quantile(x, probs = c(0.25))))) | x > (quantile(x, probs = c(0.75)) + (1.5 * (quantile(x, probs = c(0.75)) - quantile(x, probs = c(0.25)))))); return (pp)} else { return (NA)} }
dt=read.table("C:/...../test.txt",header=TRUE,sep=",")
data<-data.frame(x=dt$x,day=dt$day)
dev.new();ggplot(data, aes(x,day)) + stat_summary(fun.data=f, geom='boxplot')+stat_summary(fun.data =o, geom='point', col='red')#+ stat_summary(fun.y = o2, geom='point', col='red')