# load data:
library(plotKML)
library(dismo)
data(eberg)
data(eberg_grid)
# prepare data for spatial analysis:
eberg.xy <- eberg[runif(nrow(eberg)) < .3,]
coordinates(eberg.xy) <- ~X+Y
proj4string(eberg.xy) <- CRS("+init=epsg:31467")
# format gridded data:
gridded(eberg_grid) <- ~x+y
proj4string(eberg_grid) <- CRS("+init=epsg:31467")
# convert to a "ppp" object:
library(spatstat)
library(maptools)
eberg.ppp <- as.ppp(eberg.xy)
library(dismo)
# run MaxEnt analysis (evaluates sampling bias or mis-representation):
jar <- paste(system.file(package="dismo"), "/java/maxent.jar", sep='')
if(file.exists(jar)){
me.eberg <- MaxEnt(occurrences=eberg.ppp, covariates=eberg_grid)
## NOTE: MaxEnt can be time-consuming!
# plot the results:
par(mfrow=c(1,2), mar=c(0.5,0.5,0.5,0.5), oma=c(0,0,0,0))
image(as(me.eberg@predicted, "SpatialPixelsDataFrame"),
col=rev(heat.colors(25)), xlab="", ylab="")
points(me.eberg@occurrences, pch="+", cex=.7)
image(me.eberg@sp.domain, col="grey", xlab="", ylab="")
}Run the code above in your browser using DataLab