David Hewitt
2009-Feb-12 17:42 UTC
[R] Different labels for subsets of points in a PCA or RDA biplot
I've tried a few things both with prcomp(), and rda() and its friends in vegan (including biplot.rda and ordiplot), but can't find a solution. I'd like to associate subsets of the points in a resulting biplot ("sites" in the rda object) with different plotting colors/text styles to emphasize certain sets of points. I can't figure out how to keep the arrows (for "species" in the rda object) and then pass sets of points and their labels separately. A subproblem is finding out how to associate a vector of text labels with the coordinates in the rda object. I had no problem doing this with 'xlabs' in biplot.prcomp(), but can't get 'labels' to recognize such in ordiplot functions. -- Dave Hewitt
Gavin Simpson
2009-Feb-12 18:28 UTC
[R] Different labels for subsets of points in a PCA or RDA biplot
On Thu, 2009-02-12 at 09:42 -0800, David Hewitt wrote:> I've tried a few things both with prcomp(), and rda() and its friends > in vegan (including biplot.rda and ordiplot), but can't find a > solution. I'd like to associate subsets of the points in a resulting > biplot ("sites" in the rda object) with different plotting colors/text > styles to emphasize certain sets of points. I can't figure out how to > keep the arrows (for "species" in the rda object) and then pass sets > of points and their labels separately. A subproblem is finding out how > to associate a vector of text labels with the coordinates in the rda > object. I had no problem doing this with 'xlabs' in biplot.prcomp(), > but can't get 'labels' to recognize such in ordiplot functions.hi David, Currently most of vegan's plotting functions don't recognise vector arguments for colours/symbols etc. This is something I have been meaning to set aside time for but other work has taken precedence lately. Vegan does however provide you with all the tools to do this yourself. I'm about to head out of the office, but the general idea would be: ## continue example from ?biplot.rda ## produces 'mod' example(biplot.rda) ## grab the scores on axes you require; mod == your fitted rda/pca site.scr <- scores(mod, display = "sites", scaling = 3) spp.scr <- scores(mod, display = "species", scaling = 3) ## generate x,y lims xlims <- range(site.scr[,1], spp.scr[,1]) ylims <- range(site.scr[,2], spp.scr[,2]) ## plot what you want, but leave out sites biplot(mod, display = "species", xlim = xlims, ylim = ylims, scaling = 3) ## now add in scores as you want, to simulate we plot: ## rows 1:10 of dune in red, and ## rows 11:20 in blue. points(site.scr[1:10,], col = "red", pch = 2) points(site.scr[11:20,], col = "blue", pch = 3) The coordinates you are looking for are the things returned by scores() (with the relevant scaling applied). There is no argument 'labels' to ordiplot however, so perhaps you could provide an example of what you are doing as per the posting guide and I will try to help you. HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%