I\'m trying to use position_dodge on ggplot to obtain boxplots of two different signals (ind) sharing the same categories (cat). When there is a category with data for one
x of B has no values, so you can add "B", 0, "x" which essentially indicates that there is no distribution of "values" for x of B. The median and other percentiles are zero.
data<-data.frame(cat=c('A','A','A','A','B','B','A','A','A','A','B','B','B'),
values=c(3,2,1,4,NA,NA,4,5,6,7,8,9,0),
ind=c('x','x','x','x','x','x','y','y','y','y','y','y','x'))
Also you do not have to add position parameters here, because when you consider x as a factor, ggplot -- geom_boxplot will automagically dodge to the sides.
print(ggplot() +
scale_colour_hue(guide='none') +
geom_boxplot(aes(x=as.factor(cat), y=values, fill=ind),
data=data,
outlier.size = 1.2,
na.rm=T))
