boxplots and outliers for more than 6 set of data

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

boxplots and outliers for more than 6 set of data

mohsenhs82
Hello there,
I am trying to draw boxplot for my data. I wrote a customized function for changing whisker and outliers selection.

I did not get any points as outliers in my data, so after some investigation and some external help from some kind people, I found out the problem,

My code:
 
rm(list = setdiff(ls(), lsf.str()))
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) {   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))))))}

dt=read.table("C:/Users/msi161/Desktop/R/test.txt",header=TRUE,sep=",")
data2<-data.frame(x=dt$x,day=dt$day)
data3=data2[order(data2$day),]
data<-data.frame(x=data3$x,day=data3$day)
 dev.new();ggplot(data, aes(day,x)) +   stat_summary(fun.data=f, geom='boxplot')+stat_summary(fun.y =o, geom='point',col='red')
 

As soon as I change the amount of data it would work fine,

Works fine:
 
datadd=head(data,43*6)
dev.new();ggplot(datadd, aes(factor(day),x,fill=factor(day))) +   stat_summary(fun.data=f, geom='boxplot')+stat_summary(fun.y =o, geom='point',size=1)
 

but I am getting the following error for the 7th boxplot and later boxplots (or all of my data):

Problem:
 
datadd=head(data,43*7)
dev.new();ggplot(datadd, aes(factor(day),x,fill=factor(day))) +   stat_summary(fun.data=f, geom='boxplot')+stat_summary(fun.y =o, geom='point',size=1)
Warning message:
Computation failed in `stat_summary()`:
arguments imply differing number of rows: 1, 0
 
Any help is highly appreciated.