Search code examples
rvegan

R vegan envfit labels do not move with arrow.mul?


I am making an NMDS ordination plot in R with environmental vectors using envfit, and I have missing values in some of my environmental variables. In order not to exclude all rows from all variables containing a missing value in one variable (as with na.rm=TRUE), I have run envfit on each variable separately, but now would like to plot the results on the same plot. Thus I need to use the arrow.mul argument to make the scale of the arrows comparable to one another. And here I run into my problem: the location of the labels for the vectors do not seem to listen to arrow.mul, and labels stay in their original position, floating in space.

If someone could tell me how to get the labels to move to the new arrow point location, or suggest a workaround for the missing values, that would be fantastic. I hope I am not missing something obvious!

Here is a reproducible example of stubborn labels using the dune data from vegan:

data(dune)
data(dune.env)
de2<-dune.env[,c(1,2)]
ord<-metaMDS(dune,k=2)
plot(ord)
de2$Moisture<-as.numeric(de2$Moisture) #pretend this is numeric
ev<-envfit(ord,de2,choices=c(1,2))
ordiplot(ord,type="n")
points(ord,pch=16,col=c(1:4)[dune.env$Management])
plot(ev,arrow.mul=1,labels=list(vectors=c("A1","Moisture")),
     col="black",cex=0.9,bg="white")#floating labels
plot(ev,labels=list(vectors=c("A1","Moisture")),
     col="black",cex=0.9,bg="white")#labels are fine with no arrow.mul
plot(ev,arrow.mul=1) #default labels behave the same and float with arrow.mul

(yes I know I should learn to use ggplot, but would prefer not to just now, just for this ...)


Solution

  • This indeed is a bug in vegan. I'll fix it in github. Meanwhile, you can use plot(ev, arrow.mul = 1, rescale = FALSE) to have floating text. This will give you a warning, but it is harmless, and will work. Meanwhile I'll fix this in vegan.