Home > Net >  NMDS plot with vegan not coloured by groups
NMDS plot with vegan not coloured by groups

Time:03-12

I try to use a script to plot NMDS that worked perfectly before...but I changed of R version (R 4.1.2 on Ubuntu 20.04) and I cannot get anymore NMDS coloured graphs.

I get this error "species scores not available"

I get the good NMDS representation, but I cannot get it colored according "TypeV" -see below code - (I got it before)

mydata enter image description here

THANKS A LOT !

CodePudding user response:

The main problem is that R no longer automatically converts character data to factors so you have to do that explicitly. Here is your code with a few simplifications:

library(vegan)
data <- read.table('TESTNMDS.csv',header = T, sep = ",")
data$TypeV <- factor(data$TypeV)   # make TypeV a factor
coldit=c( "#FFFF33","#E141B9",  "#33FF66", "#3333FF")
abundance.matrix <- data[,3:50]
idx <- colSums(abundance.matrix) > 0
abundance.matrix <- abundance.matrix[ , idx]
dist_data<-vegdist(abundance.matrix^0.5, method='bray')
nmds <- metaMDS(dist_data, trace =TRUE, try=500)
plot(nmds)
orditorp(nmds,display="sites",col=coldit[data$TypeV])

You do not need a loop to eliminate columns since R is vectorized.

  • Related