View source: R/mapping_functions.R
| map_clusters | R Documentation |
Utility for mapping clusters. The function ingest an object 'cl' as returned
by find_clusters() and a shape file provisioned by the caller, along
with a string name of a column in the shape file that uniquely defines the
locations. Note that this column will be used to merge with the clusters and
therefore must aligned with the labels in 'cl' cluster locations. The
function returns a basic plotly map object that can be further modified by
the user
map_clusters(
cl,
s,
s_id,
label_id = NULL,
label = c("none", "cluster_centers", "cluster_locations", "all"),
engine = c("plotly", "ggplot"),
point_crs = NULL
)
cl |
an object of class "clusters" as returned by |
s |
shape file; must be of class sf |
s_id |
string unique identifier of 's' |
label_id |
string column of 's' that indicates display label for the row in 's' (default is NULL) |
label |
for |
engine |
string label to indicate plotting engine; either "plotly" (default) or "ggplot" |
point_crs |
optional coordinate reference system used to compute representative points when 's' is in longitude/latitude coordinates. If 'NULL', EPSG:3857 is used as a general-purpose fallback. The resulting points are transformed back to the CRS of 's' before plotting |
if (
requireNamespace("tigris", quietly = TRUE) &&
requireNamespace("ggplot2", quietly = TRUE)
) {
# get some data
dd <- example_count_data[, max(date)]
# get a distance matrix
dm <- create_dist_list("county", 50, st = "OH")
# find the clusters
cl <- find_clusters(
cases = example_count_data,
detect_date = dd,
distance_matrix = dm
)
# get shape file
ohio_shape <- tigris::counties("OH", cb = TRUE, class = "sf")
# prepare map data
md <- map_clusters(cl, ohio_shape, "GEOID")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.