## tidy density support estimate
library(ggplot2)
data(crabs, package="MASS")
crabs2 <- dplyr::select(crabs, FL, CW)
t1 <- tidy_kde(crabs2)
t2 <- tidy_ksupp(t1)
ggplot(t1, aes(x=FL, y=CW)) +
geom_contour_filled_ks(cont=c(25,50,75,95), colour="grey50") +
geom_polygon(data=t2, aes(linetype=label), fill=NA, colour=1) +
scale_linetype_manual(values="dashed", name="Support\nconvex hull")
## geospatial density support estimate
data(wa)
data(grevilleasf)
hakeoides <- dplyr::filter(grevilleasf, species=="hakeoides")
s1 <- st_kde(hakeoides)
s2 <- st_ksupp(s1, cont=97.5)
## base R plot
xlim <- c(1.2e5, 1.1e6); ylim <- c(6.1e6, 7.2e6)
plot(wa, xlim=xlim, ylim=ylim)
plot(s1, cont=c(25,50,75,97.5), add=TRUE, border="grey50")
plot(s2, add=TRUE, lty=2, pos="bottom")
## geom_sf plot
ggplot(s1) + geom_sf(data=wa, fill=NA) + ggthemes::theme_map() +
scale_linetype_manual(values=c("dashed"), name="Support\nconvex hull") +
geom_sf(data=st_get_contour(s1, cont=c(25,50,75,97.5)), aes(fill=contperc)) +
geom_sf(data=st_get_contour(s2), aes(linetype=contperc), fill=NA, col=1) +
coord_sf(xlim=xlim, ylim=ylim)
Run the code above in your browser using DataLab