Reputation: 21
I'm having trouble with this one here. I'm trying to add labels to my CCA plot, only for the species category. Normally I would include that in the aes function, however, ggplot2 isn't capable to creating cca plots, so I had to use the vegan package to create the plot, ggvegan to convert it to an object recognizable by ggplot, and then edit it as an object from there.
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")
This is the resulting CCA plot that is generated
When I create the original plot using "vegan", it labels the species, but when I convert it to a ggplot object it deletes them. Will I have to edit the plot using base R code, or is there a way to both get the species labels back and edit their size, font and colour with ggplot2?
Upvotes: 2
Views: 1591
Reputation: 9933
This is one way to do it. I've used ggrepel to reduce overlapping labels. In practice, you will probably have to select just a few species to label, unless your system is species poor
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))
Upvotes: 1