[R] ggplot2 boxplot confusion

Chris Friedl cfriedalek at gmail.com
Wed Feb 27 23:55:20 CET 2008


Thierry

1.

ggplot(mydata, aes(y = VALUE, x = SERIES)) + geom_boxplot() + facet_grid(.~
ID)

creates a grid with three ID columns (ID1, ID2, ID3) and six SERIES columns
within each ID column with two boxplots in each ID column (C10, C2) (C15,
C4), (C20, C8). I was aiming for a grid with ID columns and SERIES rows.

However if I try something like this:

ggplot(mydata, aes(y = VALUE, x = factor(1))) + geom_boxplot() +
facet_grid(SERIES ~ ID)

I get an error: 

Error: position_dodge requires the following missing aesthetics: x

Yet this works fine for a single boxplot (as you showed previously) if I
remove the facet_grid() command.

Any ideas?

Or perhaps my only recourse is to build this up programmtically, such as:

(pseudo-ish code)
for id, ser in ids, series:
  dat <- subset(mydata, (id %in% ids & ser %in% series)
  boxplot(dat) in grid position id, ser

Can I specify grid plotting grid by grid with ggplot or do I need to look at
lattice graphics? (I'd like to stick with ggplot if I can)





ONKELINX, Thierry wrote:
> 
> Chris,
> 
> 1.
> This will make more sense.
> 
> ggplot(mydata, aes(y = VALUE, x = SERIES)) + geom_boxplot() +
> facet_grid(.~ ID) 
> 
> 2.
> Now I think I understand want you want. I'm affraid that won't be easy
> because you're trying to mix continuous variables with categorical ones
> on the same scale. A density plot has two continuous scales: VALUE and
> it's density. The boxplot has a continuous scale (VALUE) and the other
> is categorical. Maybe Hadley knows a solution for your problem.
> 
> Thierry
> 
> 

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



More information about the R-help mailing list