I had a question on how to change/customize the upper and lower limit of a notch on a boxplot created by ggplot2. I looked through the function stat_boxplot and found that ggplot calculates the notch limits with the equation median +/- 1.58 * iqr / sqrt(n). However instead of that equation I wanted to change it with my own set of upper and lower notch limits.
My data has 4 factors and for each factor I calculated the median and did a bootstrap to get a 95% confidence interval of that median. Thus in the end I would like to change every boxplot to have its own unique notch upper and lower limit.
I'm not sure if this is even possible in ggplot and was wondering if people have an idea on how to do this?
Thanks again!
I guess I kind of figured it out by myself in the end but 1 down vote already?!!
Anyways I've figured out one way to customize the notches on a plot using ggplot with the function ggplot_build.
After plotting a boxplot with say:
p<-ggplot(combined,aes(x=foo,y=bar)) + geom_boxplot(notch=TRUE)
not really sure what exactly happens with ggplot_build but seems like it converts the plot into a data-frame ish structure so one can manipulate it if wanted.
gg<-ggplot_build(p)
afterwards:
gg$data[[1]]$notchlower
gg$data[[1]]$notchupper
contains the notch limits for your plot and you can basically change it with something like:
gg$data[[1]]$notchlower<-50
gg$data[[1]]$notchupper<-100
And if you had mulitple boxplots and wanted to individually change each boxplot:
gg$data[[1]]$notchlower[1]<-50
gg$data[[1]]$notchlower[2]<-50
....
gg$data[[1]]$notchlower[n]<-50
gg$data[[1]]$notchupper[1]<-100
gg$data[[1]]$notchupper[2]<-100
....
gg$data[[1]]$notchupper[n]<-100
Anyways hopefully this is a valid method to do and it would be of help for other people.