[R] ggplot2 boxplot confusion

hadley wickham h.wickham at gmail.com
Wed Feb 27 16:10:00 CET 2008


>  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.

Well one idea is:

ggplot(diamonds, aes(x = price)) + geom_density(aes(min =
-..density.., adjust= 0.5),fill="grey50", colour=NA) + facet_grid(. ~
cut) + coord_flip()

which looks like it would naturally fit with a boxplot overlaid on top
of it.  However, it's currently not possible because the boxplot is
parameterised so that it is always horizontal, while the density is
vertical - in the above example I have flipped the coordinate system,
but that flips both density plot and boxplot.

Hadly

-- 
http://had.co.nz/



More information about the R-help mailing list