Here is some code using the
contour function (but not using
ggplot2) and data from the
unmarked documentation.
# Import data
library(unmarked)
wt <- read.csv(system.file("csv","widewt.csv", package="unmarked"))
y <- wt[,2:4]
siteCovs <- wt[,c("elev", "forest", "length")]
wt <- unmarkedFrameOccu(y = y, siteCovs = siteCovs)
# Run model
fm <- occu(~ 1 ~ elev*length, wt)
# Generate list of increasing values for elev and length
ngrid <- 50 # Number of grid points
xvals <- min(siteCovs$elev, na.rm=TRUE) +
(max(siteCovs$elev, na.rm=TRUE) - min(siteCovs$elev, na.rm=TRUE))*c(0:ngrid)/ngrid
yvals <- min(siteCovs$length, na.rm=TRUE) +
(max(siteCovs$length, na.rm=TRUE) - min(siteCovs$length, na.rm=TRUE))*c(0:ngrid)/ngrid
# Generate matrix of occupancy probabilities
x.elev <- rep(xvals, ngrid+1)
y.length <- rep(yvals, each=ngrid+1)
zvals <- matrix(predict(fm, type="state", new=data.frame(elev=x.elev, length=y.length))$Predict, nrow=ngrid+1)
# Produce contour plot
contour(xvals, yvals, zvals, nlevels=10, las=1,
xlab="Elevation", ylab="Length", main="Predicted occupancy probabilities")

Jim