Re: [R] ggplot2 boxplot confusion

From: ONKELINX, Thierry <Thierry.ONKELINX_at_inbo.be>
Date: Thu, 28 Feb 2008 10:11:34 +0100

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_at_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_at_r-project.org [mailto:r-help-bounces_at_r-project.org] Namens Chris Friedl
Verzonden: woensdag 27 februari 2008 23:55 Aan: r-help_at_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_at_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.

______________________________________________
R-help_at_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.
Received on Thu 28 Feb 2008 - 09:12:37 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 28 Feb 2008 - 13:30:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive