I am trying to customize a CCA plot performed in Vegan R package. I have used a benthic cover matrix (%) vs a fish abundance matrix (number of individuals) to run this analysis. I have collected data in 4 coral reefs in 2 years. I want to have the sites dots in different colors (for reef sites) and shapes (years), fish species as text and the benthos as arrows. I have almost done it manually in ggplot, however the arrows length appear to be wrong. Comparing my plot with the "autoplot" and "plot.cca" generated plots, my arrows looks too short. My question is how can I solve this issue?
Please copy "benthos" and "fish" dataframes from this link: http://pedromeirelles.com.br/blog). The figures (ggvegan, cca.plot and ggplot) can be find in this link too. I cannot publish images here yet and the dataframes are too big. Sorry for this inconvenience.
Thank you very much in advance.
Below the scripts I have used to draw the plots.
ggplot manually draw
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
autoplot(mod)
plot.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")
I could not find differences in data plot input
fdat <- fortify(mod)
fdat
cca.benthos
vegan::scores(mod, display = "bp")