问题
I would plot points of a metaMDS
using different symbols. I would categorize the sites and plot it as points with different symbols.
I have 89 sites and I would group them in 11 groups and then plot it.
Do you have any idea how can I do this?
Thank you very much.
回答1:
Here is a simple example using base plots in vegan. There is more detail in my blog post on the subject. The key is to create a set of plotting characters for the 11 groups (pchs
below) and then index that set of characters using a factor containing the group membership (grps
below).
require("vegan")
data(dune)
set.seed(123)
sol <- metaMDS(dune)
pchs <- 1:11
grps <- factor(sample(LETTERS[1:11], nrow(dune), replace = TRUE))
## note that not all 11 groups are included in this sample
## but this is just for show - you will have a variable containing
## the group membership data
plot(sol, type = "n", display = "sites")
points(sol, display = "sites", pch = pchs[grps])
If you want more automation and are happy to use the ggplot2 package, I have started a new package, ggvegan which will do this for you. ggvegan is not on CRAN or R-forge at the moment so you'll need to build the package yourself or install it using tools from the devtools package.
require("ggvegan")
scrs <- fortify(sol)
scrs <- subset(scrs, subset = Score == "sites")
## ggplot doesn't like more than 6 groups for shape
grps <- factor(sample(LETTERS[1:6], nrow(dune), replace = TRUE))
scrs <- cbind(scrs, Group = grps) ## add on the group variable
## do the plot
ggplot(scrs, aes(x = Dim1, y = Dim2, shape = Group, colour = Group)) +
geom_point() + coord_fixed()
For more than six groups you need to specify the shapes by hand, via a scale
but that is beyond the scope of this Answer.
It is early days for ggvegan and I may well make the fortify
methods accept additional vectors to add to the fortified scores, but for now you have to add the grouping variable yourself.
来源:https://stackoverflow.com/questions/16397914/plot-points-of-metamds