[R-sig-eco] Combining output from smatr with ggplot2

Drew Tyre atyre2 at unl.edu
Wed Nov 11 02:54:02 CET 2015


>From ?geom_abline: " If the intercept and slope are stored in the data, then they can vary from panel to panel." So 

data(leaflife)

ll.sma = sma(longev~lma*site,data=leaflife)

summary(ll.sma)
# get coefficients in a data.frame
cc <- data.frame(site=1:4,coef(ll.sma))

qplot(lma, longev, data=leaflife, colour=rain) +  
  facet_wrap(~site, ncol=2) +
  geom_abline(data=cc,aes(intercept=elevation,slope=slope))
  
does what you want I think? 

--
Drew Tyre

School of Natural Resources
University of Nebraska-Lincoln
416 Hardin Hall, East Campus
3310 Holdrege Street
Lincoln, NE 68583-0974

phone: +1 402 472 4054
fax: +1 402 472 2946
email: atyre2 at unl.edu
http://snr.unl.edu/tyre
http://aminpractice.blogspot.com
http://www.flickr.com/photos/atiretoo

________________________________________
From: R-sig-ecology <r-sig-ecology-bounces at r-project.org> on behalf of Keith Bloomfield <keith.bloomfield at anu.edu.au>
Sent: Tuesday, November 10, 2015 3:23 PM
To: r-sig-ecology at r-project.org
Subject: [R-sig-eco] Combining output from smatr with ggplot2

This is a plotting question, but I hope someone on the forum might have a suggestion.

I have a dataset of leaf trait measurements made at multiple sites at two contrasting seasons.  I am interested to explore the association/line fit between a pair of traits and to differentiate the seasons at each site.

Rather than a linear regression, I would prefer to use the Standardised Major Axis approach within the smatr package:

e.g. sma.site1 <- sma(TraitA ~ TraitB * Visit, data=subset(myfile, Site=="Site1")) # testing the null hypothesis of common slopes for the two Visits (Seasons) at a given Site.


I can produce a handy lattice plot in ggplot2 with a separate panel for each Site and the points differentiated by Visit:

e.g. qplot(TraitB, TraitA, data=myfile, colour=Visit) +  facet_wrap(~Site, ncol=2)


However, if I add trend lines fitted with the additional argument in ggplot2:

+  geom_smooth(aes(group=Visit), method="lm", se=F)

......, those lines are not a good match for the sma coefficients.


What I would like to do is fit the lines suggested by the sma test onto the ggplot lattice.  Is there an easy, or efficient, way to do that?

I know that I can subset the data, produce a plot for each site, add the relevant lines with + geom_abline() and then stitch the separate plots up together with grid.arrange().  But that feels very long-winded.


I would be grateful for any pointers.


Keith Bloomfield
Postdoctoral Scientist
Atkin Laboratory
Research School of Biology
The Australian National University
46 Sullivan's Creek Road
Acton  ACT  2601

Telephone: +61 2 6125 4558
email: Keith.Bloomfield at anu.edu.au<mailto:Keith.Bloomfield at anu.edu.au>
http://biology.anu.edu.au/


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


More information about the R-sig-ecology mailing list