我会使用不同的符号绘制metaMDS
的点。我会对网站进行分类,并将其绘制为具有不同符号的点。
我有89个网站,我会将它们分成11组,然后进行绘制。
你知道我该怎么办?
非常感谢。
答案 0 :(得分:3)
以下是使用素食主义者中的基础图的简单示例。关于这个问题我的blog post有更详细的内容。关键是为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()
对于超过六个组,您需要通过scale
手动指定形状,但这超出了本答案的范围。
现在是 ggvegan 的早期阶段,我可能会让fortify
方法接受额外的向量来添加到强化分数,但是现在你必须自己添加分组变量。