View source: R/mapping_functions.R
| prepare_map_data | R Documentation |
Function ingest an clusters object as returned by find_clusters(), a
shape file, and a unique identifier for the locations in that shape file, and
prepares these objects for mapping.
prepare_map_data(cl, s, s_id, label_id = NULL, 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) |
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 |
# example code
# 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 <- prepare_map_data(cl, ohio_shape, "GEOID")
md <- prepare_map_data(cl, ohio_shape, "GEOID", label_id = "NAME")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.