# NOT RUN {
library(dismo)
files <- list.files(path=paste(system.file(package="dismo"),
'/ex', sep=''), pattern='grd', full.names=TRUE )
predictors <- raster::stack(files[c(9,1:8)]) #file 9 has more NA values than
# the other files, this is why we choose it as the first layer (see ?randomPoints)
file <- paste(system.file(package="dismo"), "/ex/bradypus.csv", sep="")
bradypus <- read.table(file, header=TRUE, sep=',')[,c(2,3,1)]
head(bradypus)
random.spec <- cbind(as.data.frame(randomPoints(predictors,50,extf=1)),species="randomSpec")
colnames(random.spec)[1:2] <- c("lon","lat")
spec.list <- rbind(bradypus, random.spec)
df <- ecospat.makeDataFrame(spec.list, expl.var=predictors, n=5000)
head(df)
plot(predictors[[1]])
points(df[df$Bradypus.variegatus==1, c('x','y')])
points(df[df$randomSpec==1, c('x','y')], col="red")
# }
Run the code above in your browser using DataLab