if(require("spatstat.explore", quietly=TRUE)) {
X <- unmark(spruces)
nsim <- 1999 # Number of simulations
nsim <- 19 # Number of simulations
env <- envelope(X, fun="Kest", nsim=nsim,
savefuns=TRUE, # save the functions
correction="translate", # edge correction for K
simulate=expression(runifpoint(ex=X))) # Simulate CSR
res <- global_envelope_test(env, type="erl")
# Default plot
plot(res)
# Plots can be edited, e.g.
# Remove legend
plot(res) + ggplot2::theme(legend.position="none")
# Change its position
plot(res) + ggplot2::theme(legend.position="right")
# Change the outside color
plot(res, sign.col="#5DC863FF")
plot(res, sign.col=NULL)
# Change default title and x- and y-labels
plot(res) + ggplot2::labs(title="95% global envelope", x="x", y="f(x)")
# Prior to the plot, you can set your preferred ggplot theme by theme_set
old <- ggplot2::theme_set(ggplot2::theme_bw())
plot(res)
# Do other edits, e.g. turn off expansion with the default limits
plot(res) + ggplot2::coord_cartesian(expand=FALSE)
# Go back to the old theme
ggplot2::theme_set(old)
# If you are working with the R package spatstat and its envelope-function,
# you can obtain global envelope plots in the style of spatstat using plot.fv:
plot.fv(res)
}
Run the code above in your browser using DataLab