我正在尝试自定义在 Vegan R 包中执行的 CCA 图。我使用了底栖覆盖矩阵 (%) 与鱼类丰度矩阵(个体数量)来运行此分析。我在 2 年内收集了 4 个珊瑚礁的数据。我想让网站点以不同的颜色(用于珊瑚礁地点)和形状(年份),鱼类作为文字,底栖动物作为箭头。我几乎已经在 ggplot 中手动完成了,但是箭头长度似乎是错误的。将我的情节与“autoplot”和“plot.cca”生成的情节进行比较,我的箭头看起来太短了。我的问题是如何解决这个问题?
请从此链接复制“benthos”和“fish”数据框:http: //pedromeirelles.com.br/blog)。这些数字(ggvegan、cca.plot 和 ggplot)也可以在此链接中找到。我还不能在这里发布图片,而且数据框太大了。很抱歉给您带来不便。
非常感谢您提前。
在我用来绘制绘图的脚本下方。
ggplot 手动绘制
library("ggplot2")
library("vegan")
library("grid")
library("ggvegan")
benthos <- please copy this dataframe from the link above
fish <- please copy this dataframe from the link above
attach(fish)
fish.num<-fish[,3:ncol(fish)]
benthos.num <-benthos[,3:ncol(benthos)]
mod <- cca(fish.num, benthos.num)
cca.res<-summary(mod)
cca.sites <-data.frame(cca.res$sites)
ord_df<-data.frame(Site=Site,Year=Year,CCA1=cca.sites$CCA1,CCA2=cca.sites$CCA2)
ord_df$Year <- factor(ord_df$Year)
ord_df$Site <- factor(ord_df$Site)
exp<-cca.res$concont
exp<-data.frame(exp$importance)
cca.species<-data.frame(cca.res$species)
cca.species<-data.frame(Cca1=cca.species$CCA1,Cca2=cca.species$CCA2,species=rownames(cca.species))
cca.benthos<-data.frame(cca.res$biplot)
cca.benthos<-data.frame(cca1=cca.benthos$CCA1,cca2=cca.benthos$CCA2, Species = rownames(cca.benthos))
ggplot(ord_df) +
geom_point(mapping = aes(x=CCA1, y=CCA2, color=Site, shape=Year),size = 4)+
geom_text(data = cca.species,
aes(x = Cca1, y = Cca2, label = species),
size = 3,alpha=0.4,colour = "darkred") +
geom_segment(data = cca.benthos,
aes(x = 0, xend = cca1, y = 0, yend = cca2),
arrow = arrow(length = unit(0.5, "cm")), size=1, colour = "grey") +
geom_text(data = cca.benthos,
aes(x = cca1*1.5, y = cca2*1.5, label = Species),
size = 5) +
labs(list(title = NULL, x = paste("CCA1 (",round(exp[2,1]*100,digits=2),"%)"), y = paste("CCA2 (",round(exp[2,2]*100,digits=2),"%)"))) +
geom_hline(yintercept = 0, colour = "gray70") +
geom_vline(xintercept = 0, colour = "gray70") +
scale_colour_manual(values=c("#43CD80","#9400D3","steelblue3","#DEB887"))+
theme_bw()+
theme(panel.border = element_rect(colour = "white", size=1))+
theme(legend.key=element_rect(fill='white'))+
theme(legend.key = element_rect(colour = "white"))+
theme(axis.title.x = element_text(face="bold", size=14))+
theme(axis.title.y = element_text(face="bold", size=14))+
theme(axis.text.x = element_text(size=14,color="black"))+
theme(axis.text.y = element_text(size=14,color="black"))+
theme(axis.line.x=element_blank())+
theme(axis.line.y=element_blank())+
theme(
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank())
ggvegen 自动绘图
autoplot(mod)
情节.cca
plot(mod, type="n")
text(mod, dis="bp")
points(mod, display="sites",pch=21, col="red", bg="yellow", cex=1.2)
text(mod, "species", col="blue", cex=0.8)
text(mod, display = "sites", cex=0.7, col="red")
我找不到数据图输入的差异
fdat <- fortify(mod)
fdat
cca.benthos
vegan::scores(mod, display = "bp")