-----Original Message-----
From: anna at ecology.su.se
Sent: Tue, 19 Feb 2013 12:38:25 +0100
To: r-help at r-project.org
Subject: [R] introducing jitter in overlapping graphs using ggplots
(plotmeans). Also sciplot.
Hi,
I want to plot means with standard deviations of Total Nitrogen (TN)
across
4 stations (S1-S4) and over 3 years (2007-2009). I want this plot in one
panel.
I do not want medians (bwplot, boxplot).
I have tried a few different packages and it seems that ggplots with
plotmeans was the fastest (I am not extremely skilled in writing my own
scripts). Unfortunately, there is no grouping argument in plotmeans().
Therefore, I have overlaid three plots (plotting all stations witin
year).
However, as the graphs are exctly overlaid, it is not possible to
distinguish the confidence intervals. How do I introduce jitter?
Data2007, Data2008 and Data2009 are the dataframes with the data from
that
particular year including all the stations.
I have also tried lineplot.CI from the package sciplot and also there I
am
not able to introduce jitter. I have looked at the helpfiles.
PACKAGE GGPLOT:
library(gplots)
par(family="serif",font=1)
plotmeans(TN ~ STATION,
data =Data2007,
bars=TRUE, p=0.95,
pch=1,
cex=0.8,
n.label=FALSE,
mean.labels=FALSE,
barwidth=1.5, barcol="black",
connect=TRUE,
xlab="Station",
ylab = expression(paste("TN (",mu, g~L^{-1}, ")")))
par(new=T)
plotmeans(TN ~ STATION,
data =Data2008,
bars=TRUE, p=0.95,
pch=2,
cex=0.8,
lty=2,
n.label=FALSE,
mean.labels=FALSE,
barwidth=1.5, barcol="black",
connect=TRUE,
na.action=na.exclude,
yaxt='n', ann=FALSE,
xaxt="n")
par(new=T)
plotmeans(TN ~ STATION,
data =Data2009,
bars=TRUE, p=0.95,
pch=3,
cex=0.8,
lty=3,
n.label=FALSE,
mean.labels=FALSE,
barwidth=1.5, barcol="black",
connect=TRUE,
na.action=na.exclude,
yaxt='n', ann=FALSE,
xaxt="n")
PACKAGE SCIPLOT:
library(sciplot)
lineplot.CI(response=TN, x.factor=STATION, group=YEAR,
ci.fun= function(x) c(mean(x)-sd(x), mean(x) + sd(x)),
data = Mydata,
xlab="Station",
ylab = expression(paste("TN(",mu, g~L^{-1}, ")")))
#here I have calculated the standard deviations instead of the default
standard errors.
Thank you for taking your time. I have spent a long time trying to solve
this and the frustration slowly approaches anger (in myself) :-)
Yours sincerely
Anna Zakrisson Braeunlich
PhD Student
Department of Systems Ecology
Stockholm University
Svante Arrheniusv. 21A
SE-106 91 Stockholm
Lives in Berlin.
For fast paper-mail responses, please use the below address:
Katzbachstr. 21
D-10965, Berlin - Kreuzberg
Germany/Deutschland
E-mail: anna at ecology.su.se
Tel work: +49-(0)3091541281
Mobile: +49-(0)15777374888
Web site: http://www.ecology.su.se/staff/personal.asp?id=163