[R] Re creating Procrustes Plot in Lattice
Gavin Simpson
gavin.simpson at ucl.ac.uk
Wed Jul 30 18:37:10 CEST 2008
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.
Give it a go, but if you get stuck then mail me back privately (note I
am moving house at the weekend so I'm not going to get back to you any
time real soon!) or post a message on the vegan development website:
https://r-forge.r-project.org/forum/forum.php?forum_id=194
and Jari may be able to help you - I might also chip in there once I
unpack my belongings and get my head round how to pass this stuff around
in lattice...
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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
More information about the R-help
mailing list