Search code examples
rvegan

How to change the color in the vegan graph? (bray)


Here is my code

library(vegan)
library(MASS)


row.names(Data) <- c("SI1", "SII0", "SI0", "SII2", "SI2", "SII1", "SIII0", "SIV2", "SIII2", "SIV1", "SIII1", "SIV0")
bcdist <- vegdist(Data, "bray")

bcmds <- isoMDS(bcdist, k = 2)


plot(bcmds$points, type = "n", xlab = "", ylab = "")

text(bcmds$points, dimnames(Data)[[1]])

Then I get this graph. How do I add colors for every point in the graph? Thank you

Here is my data


Solution

  • Specify a colour for each point/group or use a pre-made colour pallet (must be at least as long as your number of groups):

    cols <- c("red", "blue", "green"....etc)
    

    Then include the col argument in the plotting function, choosing a label colour based on your row names:

    text(bcmds$points, dimnames(Data)[[1]], col = cols)