Plot points of metaMDS

假装没事ソ 提交于 2019-12-11 01:12:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!