Dear Andreas,
melt() and cast() are nice tools for this kind of problems. They both
reside in the reshape package that automatic loaded when ggplot2 is.
a <- rnorm(100)
b <- rnorm(100,1,2)
c <- rnorm(100,2,0.5)
ds <- data.frame(a = a, b = b, c = c)
library(ggplot2) # loads qqplot2
ggplot(melt(ds), aes(x = variable, y = value)) + geom_boxplot()
HTH,
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
To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey
-----Oorspronkelijk bericht-----
Van: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
Namens Andreas Christoffersen
Verzonden: dinsdag 21 april 2009 16:42
Aan: r-help at r-project.org
Onderwerp: [R] ggplot2 - boxplot of variables / columns
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
______________________________________________
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.
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in this message
and any annex are purely those of the writer and may not be regarded as stating
an official position of INBO, as long as the message is not confirmed by a duly
signed document.