[R] introducing jitter in overlapping graphs using ggplots (plotmeans). Also sciplot.
John Kane
jrkrideau at inbox.com
Tue Feb 19 16:07:24 CET 2013
Hi Anna,
A small point -- there is no package called ggplots. There is a package called gplots and one called ggplot2, which in earlier form was called ggplot.
To see what is happening I believe we need some sample data from the three data files or some mock-up data that matches your actual data in form.
The easiest way to supply data is to use the dput() function. Example with your file named "testfile":
dput(testfile)
Then copy the output and paste into your email. For large data sets, you can just supply a representative sample. Usually,
dput(head(testfile, 100)) will be sufficient.
In this case it looks like we would want three dput results, one for each year.
John Kane
Kingston ON Canada
> -----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
>
> ><((((B:>`b?". . b?" `b?". .b?" `b?". . ><((((B:>`b?". . b?" `b?". .b?"
> `b?". .><((((B:>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!
More information about the R-help
mailing list