You are making this more complicated than it really needs to be; messing with formulas and passing unevaluated arguments always causes, if not problems, headaches when you start writing functions.
Instead, use the default versions of the respective functions, which take an ordination object and a variable to plot as the arguments instead of a formula.
Here is a version that does just that:
plot_spcSurface <- function(ord, speFrame, speName, scal=2 ) {
ef <- envfit(ord, speFrame[[speName]])
sf <- ordisurf(ord, speFrame[[speName]], plot = FALSE, scaling = scal)
plot(ord, type="po", scaling = scal)
spe.sc <- scores(ord, choices=1:2, display="sp", scaling = scal)
arrows(0, 0, spe.sc[, 1], spe.sc[, 2], length=0, lty=1, col="red")
ordilabel(ord, dis="sp", cex=0.8, col="red", scaling = scal)
plot(ef, labels = speName)
plot(sf, col = "darkgreen", add = TRUE)
invisible()
}
plot_spcSurface(rdam, varespec, "Cal.vul")
## or in the development version of vegan >= 2.1-41
plot_spcSurface(rdam, varespec, "Callvulg")
The only issue now is that due to my not accounting for the case where there are no labels stored on the internal object that is returned from envfit()
, the function above doesn't label the arrow correctly. It should, but there is a corner case that I didn't account for in plot.envfit()
, which I'll now go an fix on R-forge. This was fixed in r2862 on R-forge. (Note that in that version, Jari has changed the species codes so you'll need "Callvulg"
now instead of "cal.vulg"
.)