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")