# \donttest{
library(sf)
data(pu)
d <- dispersion(st_drop_geometry(pu[,2:ncol(pu)]))
p <- d[,"H"]
clr <- c("#3288BD", "#99D594", "#E6F598", "#FEE08B",
"#FC8D59", "#D53E4F")
clrs <- ifelse(p < 0.5524462, clr[1],
ifelse(p >= 0.5524462 & p < 1.223523, clr[2],
ifelse(p >= 1.223523 & p < 2.465613, clr[3],
ifelse(p >= 2.465613 & p < 4.76429, clr[4],
ifelse(p >= 4.76429 & p < 8.817699, clr[5],
ifelse(p >= 8.817699, clr[6], NA))))))
plot(st_geometry(pu), col=clrs, border=NA)
legend("bottomleft", legend=rev(c("Very Rare","Rare","Moderately Rare",
"Somewhat Common","Common","Over Dispersed")),
fill=clr, cex=0.6, bty="n")
box()
# }
Run the code above in your browser using DataLab