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

Keith Bloomfield keith.bloomfield at anu.edu.au
Tue Nov 10 22:23:33 CET 2015


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]]



More information about the R-sig-ecology mailing list