# uhcdensplot

Function to plot the density of the environmental characteristics at the observed locations in the test data set, $$f^u(z)$$, along with a simulation envelope for $$f^U(z)$$ created by randomly choosing locations in the test data using the uhcsim or uhcsimstrat function.

• densdat = estimated density of used points in test data set
• densrand = predicted densities of used points in the test data set
• includeAvail = indicator determining whether the available distribution should be drawn on the plot
• avail = estimated density of available points in the test data set
• xl = x-axis limits (can be user supplied)
• yl = y-axis limits (can be user supplied)
uhcdensplot <- function(densdat, densrand, includeAvail, densavail, xl=NULL,
yl=NULL){
# combine to get reasonable axis limits
alldens <- c(densrand, densdat$y, densavail$y)
if (is.null(yl)){
yl <- c(min(alldens), max(alldens))
}

# mean predicted density
mean.f <- apply(densrand,2,mean, na.rm=TRUE)
#lower sim envelope
low.f <- apply(densrand,2,quantile, prob=0.025, na.rm=TRUE)
# upper sim envelope
up.f <- apply(densrand,2,quantile, prob=0.975, nar.rm=TRUE)
if (is.null(xl)!= TRUE){
plot(densdat$x, densdat$y, ylim=yl, xlab="",
type="n", ylab="Density", xlim=xl)
}else{
plot(densdat$x, densdat$y, ylim=yl, xlab="", type="n", ylab="")
}

# Observed and predicted density of f^u
polygon(x = c(densdat$x, rev(densdat$x)),
y = c(up.f, rev(low.f)), col="gray", border="gray")
lines(densdat$x, densdat$y, ylim=yl, xlab="",
type="l", ylab="", col="red", lty=2, lwd=2)

# Include available if includeAvail=TRUE
if (includeAvail==TRUE){
lines(densavail$x, densavail$y, lwd=2)
}
}


spun with ezspin(“uhcplots/functions/uhcdensplot.R”, out_dir = “uhcplots/output”, fig_dir=“uhcplots/figures”, keep_md=F)