rplotlabelpcarda

change labels in a plot in R


I am trying to add a different label to my points in a cca plot. Here it is a reproducible example:

## load vegan
require("vegan")
## load the Dune data
data(dune, dune.env)
## PCA of the Dune data
mod <- rda(dune, scale = TRUE)
## plot the PCA
plot(mod, scaling = 3)
## build the plot up via vegan methods
scl <- 3 ## scaling == 3
colvec <- c("red2", "green4", "mediumblue")
plot(mod, type = "n", scaling = scl)
with(dune.env, points(mod, display = "sites", col = colvec[Use],
                      scaling = scl, pch = 21, bg = colvec[Use]))

with(dune.env, legend("topright", legend = levels(Use), bty = "n",
                      col = colvec, pch = 21, pt.bg = colvec))
text(mod, display = "sites", scaling = scl, cex = 0.8, col = "darkcyan")

I would like to change the last row of the code: Instead of displaying "sites" (automatically it displays the row name) I would like to display another variable, for example the variable "Management". Thanks in advance.


Solution

  • You just need to specify the labels parameter. If the text is printed exact at the point, it makes it hard to read, so I also added pos=3 to make the text appear slightly above the points.

    text(mod, labels=dune.env$Management, pos=3, scaling=scl, cex=0.8, col="darkcyan")
    

    Text Labels