Gabe,
Since you didn't provide a small example of your data, I can't test out
your code. However, I used an example from the ?ordiellipse help page to
draw different colored ellipses (using the show.groups= argument) with
labels (using the label= argument).
Hope this helps.
library(vegan)
data(dune)
data(dune.env)
mod <- cca(dune ~ Management, dune.env)
attach(dune.env)
plot(mod, type="n")
points(mod, display="sites", pch=as.numeric(Management),
col=as.numeric(Management))
groupz <- sort(unique(Management))
for(i in seq(groupz)) {
ordiellipse(mod, Management, kind="se", conf=0.95, label=T,
font=2, cex=1.5, col=i, show.groups=groupz[i])
}
Jean
`·.,, ><(((º> `·.,, ><(((º> `·.,, ><(((º>
Jean V. Adams
Statistician
U.S. Geological Survey
Great Lakes Science Center
223 East Steinfest Road
Antigo, WI 54409 USA
From:
Gabriel Yospin <[email protected]>
To:
[email protected]
Date:
08/09/2011 10:34 PM
Subject:
[R] Plotting Ellipses and Points of Matching Colors in an Ordination
Sent by:
[email protected]
Hello, R-Help -
I am trying to plot the results of an ordination from package vegan. The
tricky part for me right now is getting the colors of the ellipses
denoting
the 95% confidence intervals of the group centroids to match the colors of
the points for those same groups.
>From and earlier post, I saw the code to make a plot of the ordination
using
different colors for my different groups. My functional code is below:
library(vegan)
comvars <- read.csv("commvars9trim2.csv")
com.mds <- metaMDS(comvars, trace=FALSE)
firefactors <- read.csv("commvars9factors.csv")
plot(com.mds, type = "n")
points(com.mds, dis="si", pch = as.numeric(firefactors$comm4), col =
as.numeric(firefactors$comm4))
This code will generate the ordination and plot it, using the factor
levels
from firefactors$comm4 to determine the colors and characters to use in
the
plot.
What I would like to do next is plot the ellipses denoting the 95%
confidence intervals of the group centroids, with colors matching those of
the points. The following piece of code plots the centroids:
with(firefactors, ordiellipse(com.mds, comm4, kind = "se", conf = 0.95,
col
= as.numeric(firefactors$comm4)), label = TRUE)
But the above code makes all of the ellipses blue. Blue is the fourth
color
in my default palette(), and the first value returned by
as.numeric(firefactors$comm4) is 4. I assume that's not a coincidence, but
I
could be wrong.
I have also tried using:
plot(com.mds, display = "sites", type = "p")
with(firefactors, ordiellipse(com.mds, comm4, kind = "se", conf = 0.95,
col
= as.numeric(firefactors$comm4))
But that code also gives me blue ellipses.
Finally, I'd like to label the ellipses. The only way I've found to do
that
is by using the ordispider() function. Is there any way to make ordispider
draw no lines? I've tried
with(firefactors, ordispider(com.mds, comm4, col = "green3", label = TRUE,
lty = 3))
My two questions:
1. How do I make the ellipse color match the color of the points each
ellipse represents?
2. How do I label those ellipses, without drawing the dashed lines as per
ordispider()?
Many thanks,
Gabe
--
Gabriel I. Yospin
Center for Ecology & Evolutionary Biology
Bridgham Lab
University of Oregon
Eugene, OR 97403-5289
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.