After a bit of research on gg_ordisurf
github source code, the problem was coming from this part of the code function:
# Calculate default binwidth
# Can change the binwidth depending on how many contours you want
if(missing(binwidth)) {
r <- range(env.var)
binwidth <- (r[2]-r[1])/15
} else {
binwidth = binwidth
}
so I added na.rm=TRUE
in the range
function:
# MODIFED gg_ordisurf function
if(missing(binwidth)) {
r <- range(env.var, na.rm = TRUE)
binwidth <- (r[2]-r[1])/15
} else {
binwidth = binwidth
}
and made my own gg_ordisurf function by copying the source code.
Note: the vegan::ordisurf
function was working perfectly fine with this issue.