[R] ggplot2 - boxplot of variables / columns

Andreas Christoffersen achristoffersen at gmail.com
Tue Apr 21 16:42:06 CEST 2009


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?

What is the simple to compare multiple variables like this?

thanks in advance




More information about the R-help mailing list