我会metaMDS
使用不同的符号绘制点。我会将站点分类并将其绘制为具有不同符号的点。
我有 89 个站点,我会将它们分成 11 个组,然后绘制它。
你知道我该怎么做吗?
非常感谢。
这是一个在vegan中使用基图的简单示例。我的博客文章中有更多关于该主题的详细信息。关键是为 11 个组(pchs
下)创建一组绘图字符,然后使用包含组成员身份的因子(下)索引该组字符grps
。
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])
如果你想要更多的自动化并且乐于使用ggplot2包,我已经开始了一个新的包,ggvegan它将为你做这件事。ggvegan目前不在 CRAN 或 R-forge 上,因此您需要自己构建包或使用devtools包中的工具安装它。
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()
对于超过六个组,您需要通过 a 手动指定形状,scale
但这超出了本答案的范围。
ggvegan还处于早期阶段,我可能会让这些fortify
方法接受额外的向量以添加到强化分数中,但现在您必须自己添加分组变量。