[R] plotting group means

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Tue Sep 9 13:56:51 CEST 2008

Dear Erich,

Have a look at ggplot2

dataset <- expand.grid(x = 1:20, y = factor(LETTERS[1:4]), value = 1:10)
dataset$value <- rnorm(nrow(dataset), sd = 0.5) + as.numeric(dataset$y)
plotdata <- aggregate(dataset$value, list(x = dataset$x, y = dataset$y),
plotdata <- merge(plotdata, aggregate(dataset$value, list(x = dataset$x,
y = dataset$y), sd))
plotdata$min <- plotdata$x.x - plotdata$x.y
plotdata$max <- plotdata$x.x + plotdata$x.y
ggplot(plotdata, aes(x = x, y = x.x, colour = y, min = min, max = max))
+ geom_pointrange() + geom_line() + geom_point()



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
tel. + 32 54/436 185
Thierry.Onkelinx op 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
~ John Tukey

-----Oorspronkelijk bericht-----
Van: r-help-bounces op r-project.org [mailto:r-help-bounces op r-project.org]
Namens Erich Studerus
Verzonden: dinsdag 9 september 2008 12:49
Aan: r-help op r-project.org
Onderwerp: [R] plotting group means

Hi all,

I want to plot the grouped means of some variables. The dependent
and the grouping factor are stored in different columns. I want to draw
simple line-plot of means, in which the x-axis represents the variables
y-axis represents the means. The means of the groups should be connected
lines. So far, the only function that I could find comes closest to what
looking for, is the error.bars.by-function in the psych-package. To
what I'm looking for, just type:

x <- matrix(rnorm(500),ncol=20)
y <- sample(4,25 ,replace=TRUE)
x <- x+y

Now, I want to put a legend for the grouping factor of this graph. I
would like to manipulate the linetypes and colors of the lines. I've
the documentation, but it was not clear to me, how to do this. Are there
other plotting functions in R, which can do the same?



Erich Studerus
Lic. Phil. Klinische Psychologie
Psychiatric University Hospital Zurich
Division of Clinical Research
Lenggstr. 31
CH-8008 Zurich
Mail: erich.studerus op bli.uzh.ch
Office: +41 44 384 26 66
Mobile: +41 76 563 31 54

	[[alternative HTML version deleted]]

R-help op r-project.org mailing list
PLEASE do read the posting guide
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.

More information about the R-help mailing list