[R] ggplot2 - boxplot of variables / columns
David Winsemius
dwinsemius at comcast.net
Tue Apr 21 17:14:03 CEST 2009
On Apr 21, 2009, at 10:42 AM, Andreas Christoffersen wrote:
> Hi,
>
> ggplot/qplot is great - it has really helped me do some nice things.
> However, simple boxplot of different columns/variables is a bit
> tricky, because of (i think) qplot's generic Y conditional on X input
> form. Se below.
>
> # Some data:
> a <- rnorm(100)
> b <- rnorm(100,1,2)
> c <- rnorm(100,2,0.5)
> # normal boxplot of a,b,c
> boxplot(a,b,c) # Looks good
> library(ggplot2) # loads qqplot2
> # Tries do replicate the simple boxplot
> qplot(a,b,c, geom="boxplot") # Not good
> # Workaround
> d <- c(a,b,c)
> e <- c(rep("a",100),rep("b",100),rep("c",100))
> qplot(e,d,geom="boxplot") # Works - but there must be a simpler way?
qplot(ind, values, data=stack(data.frame(a,b,c)), geom="boxplot")
I first tried stack(list(a,b,c)) but did not get the expected results.
If anyone wants to enlighten me on why, I would be happy to offer a
rewrite of the stack help page that clarifies my inability to parse it
correctly in its current incarnation.
>
> What is the simple to compare multiple variables like this?
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list