我在这里遇到这个问题。我正在尝试为我的CCA图添加标签,仅针对物种类别。通常我会在aes函数中包含它,但是,ggplot2不能创建cca图,所以我不得不使用素食包创建绘图,ggvegan将其转换为ggplot可识别的对象,然后编辑它从那里作为一个对象。
cca <- cca(sp_matrix~average+bpi_st_fi+northing+easting+slope+depth,
data=mollusca)
plot(cca)
summary(cca)
ccaplot <- autoplot(cca)
ccaplot +
lims(x = c(-2.5, 2.5)) + lims(y = c(-2.5,2.5)) +
theme(panel.background = element_blank()) + geom_hline(aes(yintercept=0),
colour="#8c8c8c") +
geom_vline(aes(xintercept=0), colour="#8c8c8c")
这是生成的CCA图
当我使用“素食主义者”创建原始图表时,它会标记物种,但是当我将其转换为ggplot对象时,它会删除它们。我是否必须使用基本R代码编辑绘图,或者是否有办法将物种标签返回并使用ggplot2编辑其大小,字体和颜色?
答案 0 :(得分:1)
这是一种方法。我使用ggrepel来减少重叠标签。在实践中,您可能只需选择几个物种进行标记,除非您的系统是物种差的
library("vegan")
library("ggvegan")
library("ggrepel")
data("dune")
data("dune.env")
CCA <- cca(dune ~ ., data = dune.env[,1:3])
sp <- fortify(CCA, display = "sp")
autoplot(CCA) +
geom_text_repel(data = sp, mapping = aes(x = CCA1, y = CCA2, label = Label))