Skip to content
Back to formatted view

Raw Message

Message-ID: <C1DBB934-D242-4AF4-B0F6-29110A255B9C@comcast.net>
Date: 2009-04-21T15:14:03Z
From: David Winsemius
Subject: ggplot2 - boxplot of variables / columns
In-Reply-To: <290f574f0904210742x70a6bd93jec8a80a779873841@mail.gmail.com>

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