[R] ggplot2 boxplot confusion
ONKELINX, Thierry
Thierry.ONKELINX at inbo.be
Thu Feb 28 10:11:34 CET 2008
Chris,
You need to specify position = "identity"
library(ggplot2)
series <- c('C2','C4','C8','C10','C15','C20')
series <- factor(series, levels = series)
ids <- c('ID1','ID2','ID3')
mydata <-
data.frame(SERIES=rep(series,30),ID=rep(ids,60),VALUE=rnorm(180), dummy
= factor(1))
ggplot(mydata, aes(y = VALUE, x = dummy)) + geom_boxplot(position =
"identity") + facet_grid(SERIES ~ ID)
Thierry
------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be
www.inbo.be
Do not put your faith in what statistics say until you have carefully
considered what they do not say. ~William W. Watt
A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney
-----Oorspronkelijk bericht-----
Van: r-help-bounces op r-project.org [mailto:r-help-bounces op r-project.org]
Namens Chris Friedl
Verzonden: woensdag 27 februari 2008 23:55
Aan: r-help op r-project.org
Onderwerp: Re: [R] ggplot2 boxplot confusion
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.
______________________________________________
R-help op r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list