[R] Re creating Procrustes Plot in Lattice
Dylan Beaudette
dylan.beaudette at gmail.com
Wed Jul 30 19:24:28 CEST 2008
On Wednesday 30 July 2008, Gavin Simpson wrote:
> On Wed, 2008-07-30 at 04:59 -0700, Andrewjohnclose wrote:
> > Hi, I have been trying to create a function to generate a Procrustes
> > plot, generated from package "vegan"
> > in lattice.
> >
> > standard vegan code as follows
> > library(vegan)
> > pro=protest(P1, P8, permutations=4999,choices=1:4)
> > plot(pro)
> >
> > Now, here is the code for the function that I have failed to get to work
> > properly.
> >
> > panel.procrustes=function(x,y)
> > }Pro=protest(x,y,permutations=4999,choices=1:4)
> > Proplot=plot(Pro)
> > }
> > xyplot(P1[1:4]~P8[1:4],panel=panel.procrustes)
> >
> > I can generate an empty plot, but not much else - hope someone can help
> > and point out the obvious!
> >
> > Kind regards
> >
> > Andrew
>
> The obvious thing is that whole thing is wrong! ;-)
>
> What's wrong with the standard plot?
>
> You are trying to mix base (standard) graphics functions with
> grid/lattice graphics and this is not possible (well Ok there is package
> gridBase).
>
> You'll have to start doing the plotting from scratch in
> panel.procrustes. You might get some ideas of how to do this by looking
> at the ordixyplot functions and panel functions in current vegan that
> implement lattice graphics plots for ordiplot objects. I'm not
> sufficiently familiar with Lattice yet to advise how to go about
> producing a panel function, but the basic elements are:
>
> * draw the points from x$Yrot[, 1:2]
> * draw the arrows from x$Yrot[, 1:2] to x$X[, 1:2]
> * draw the origin - equivalent of abline(h = 0) and abline(v = 0)
> * draw the rotation involved in the Procrustes analysis: abline(0,
> tan(acos(x$rotation[1, 1])) and abline(0, 1/tan(acos(-x
> $rotation[1, 1]))
>
> So you'll need the Lattice equivalents of abline and then work out how
> to pass the X, Yrot and rotation components to your panel function. This
> is the bit I'm not clear on but look at ordixyplot and panel.ordi for
> inspiration.
>
Here is a relatively simple demonstration of creating a custom panel function:
http://casoilresource.lawr.ucdavis.edu/drupal/node/630
Cheers,
Dylan
--
Dylan Beaudette
Soil Resource Laboratory
http://casoilresource.lawr.ucdavis.edu/
University of California at Davis
530.754.7341
More information about the R-help
mailing list