#' Calculate Minimum Convex Polygon (MCP) of points observations.
#'
#' @param x An sf points object.
#' @param percentile The percentile of points (distance from centroid) excluded
#' before calculating the MCP.
#'
#' @return A sf polygon object representing the MCP.
#' @export
mcp <- function(x, percentile=95){
centroid <- sf::st_centroid(sf::st_union(x))
dist <- as.numeric(sf::st_distance(x, centroid))
within_percentile_range <- dist <= quantile(dist, percentile/100)
x_filter <- st_union(x[within_percentile_range,])
st_convex_hull(x_filter)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.