[R] ggplot2 boxplot confusion

Chris Friedl cfriedalek at gmail.com
Wed Feb 27 05:58:10 CET 2008


Ultimately my aim is to get a plot of density faceted by 2 factors with a
horizontal boxplot overlaid on each density plot in the grid to indicate
summary stats. So I've been experimenting with creating boxplots and density
plots. Here's some representative data.

series = c('C2','C4','C8','C10','C15','C20')
ids = c('ID1','ID2','ID3')
mydata <- data.frame(SERIES=rep(cases,30),ID=rep(ids,60),VALUE=rnorm(180))

1. Using R default graphics I can create a boxplot of data independent of
factors as follows:
boxplot(mydata$VALUE)

But I can't see how to do this with ggplot2. All the examples in the help
show x and y aesthetics. How to boxplot a single vector? (I saw a reference
to a "group" parameter in R-help somewhere but can't find it in the ggplot2
help pages. Is this a case of group = identity ?)

2. I've read the density plot help and noticed the reference to ..density..
as a means to pass density data instead of original data. But I can't seem
to get a boxplot to overlay a density plot. This is what I've got so far
with consequent error message:

m <- ggplot(mydata, aes(x=VALUE))
m + geom_density()+ geom_boxplot(aes(x=..density..))

Error in data.frame(..., check.names = FALSE) : 
  arguments imply differing number of rows: 0, 180

I've tried y=..density.., both x= and y =  ..density.. and neither and all
fail somehow. Problem is I don't really understand what I'm doing at this
point.

So can anyone help me out with this? thanks







-- 
View this message in context: http://www.nabble.com/ggplot2-boxplot-confusion-tp15706116p15706116.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list