0

I ran metaMDS and want to plot and color code by a grouping based on certain data frame characters. In my original data frame, df$yr are years and df$2 are sites. I want to color by the years.

caltmds <- metaMDS(df[,3:12], k=3)
plot(caltmds, type = 'n')
cols <- c("red2", "mediumblue")
points(caltmds, col = cols[df$yr])

I also tried from this post:

scl <- 3
colvec <- c("red2", "mediumblue")
plot(caltmds, type = "n", scaling = scl) 
with(df, points(caltmds, display = "sites", col = colvec[yr], pch = 21, bg = colvec[yr]))
text(caltmds, display = "species", cex = 0.8, col = "darkcyan")
with(df, legend("topright", legend = levels(yr), bty = "n", col = colvec, pch = 21, pt.bg = colvec))

Nothing plots

KNN
  • 459
  • 4
  • 19

1 Answers1

0
#DATA
df1 = mtcars

mycolors = df1$cyl   #Identify the grouping vector

library(vegan)
m = metaMDS(df1)

x = scores(m)  #Extract co-ordinates

plot(x, col = as.numeric(as.factor(mycolors)))
d.b
  • 32,245
  • 6
  • 36
  • 77
  • Your code: `x = scores(m) #Extract co-ordinates` is what I was missing! This colors the points on the plot by the two years - as I wanted. I will see if I can build out from here now to add on labels, legend, etc. – KNN Feb 23 '19 at 16:56