Choropleth map
Description
Plots a choropleth map of covariates, case counts, or incidence rates.
plot_map(
data,
var,
time,
unit = NULL,
map,
type = "cov",
pop = NULL,
pt = 1e+05,
map_unit = NULL,
aggregate_time = "year",
aggregate_time_fun = "mean",
transform = "identity",
title = NULL,
var_label = NULL,
palette = NULL,
centering = NULL,
bins = NULL,
bins_method = "quantile",
bins_label = NULL,
coordgrid = FALSE,
...,
area = NULL,
map_area = NULL,
by_year = NULL
)Arguments
data: Data frame containing equally spaced (daily, weekly, monthly) covariate or case observations for one or multiple locations.var: Name of the column identifying the variable to be plotted.time: Name of the variable that identifies the temporal dimension of the data frame. Its values must be in date format (“yyyy-mm-dd”) representing the day of observation for daily data, the first day of the week for weekly, or the first day of the month for monthly observations.unit: Name of the variable that identifies the different units for which a time series is available, typically a spatial unit.map:sfobject corresponding to the spatial unit specified in ‘unit’.type: Character that specifies the type of variable invar. Possible values include ‘cov’ (covariate, default), ‘counts’ (case counts), and ‘inc’ (case incidence). Iftype='inc',popis required.pop: Character identifying the variable name for population. Only needed iftype='inc'.pt: Scale of the person-time (default 100,000) for incidence rates.map_unit: Name of the variable that identifies the different units in the map object. If not specified, it assumes the same name as inunit.aggregate_time: Temporal scale for visualization and aggregation. Options include “all” (across all time points) and “year” (default).aggregate_time_fun: Character indicating the function to be used in the aggregation over time fortype="cov". Options are “mean” (default), “median”, “sum”. For case counts and incidence, “sum” is always applied.transform: Character, defaults to “identity” (i.e., no transformation). Transforms the color ramp for better visualization. Useful options include “log10p1”log10(x+1)for case counts and incidence with 0s, or any of the in-built ggplot2 options such as “log10”log10(x), “log1p”log(x+1), and “sqrt”sqrt(x)(check all possible options using?scale_y_continuous).title: Optional title of the plot.var_label: Character with a custom name for the case or covariate variable.palette: GHR, RColorBrewer or colorspace palette. Use “-” before the palette name (e.g., “-Reds”) to reverse it.centering: Numerical or “median”, defaults to NULL. If set, it centers the palette on that value.bins: Number of bins for categorization of numerical variables. Defaults to NULL (no binning). Can’t be used if usingcenteringortransform.bins_method: Method to compute the bins, only used whenbinsis not NULL. Possible values are “quantile” (default) and “equal”.bins_label: Optional labels for the bins. They must have the same length as the number of bins. Defaults to NULL (default interval labels).coordgrid: Boolean indicating whether the coordinate grid should be included in the visualization. Defaults to FALSE....: Additional arguments to be passed togeom_sf. Possible values includecolour(e.g.,colour="black"), linewidth (e.g.,linewidth=0.1), linetype (e.g.,linetype=2), and alpha (e.g.,alpha=0.8).area: Deprecated, useunitinstead.map_area: Deprecated, usemap_unitinstead.by_year: Defunct. Use ‘aggregate_time’ instead.
Returns
A ggplot2 choropleth map.
Examples
# Load data
library("sf")
data("dengue_MS")
data("map_MS")
# Temporal average of a covariate
plot_map(
data = dengue_MS,
var = "tmin",
time = "date",
type = "cov",
unit = "micro_code",
map = map_MS,
map_unit = "code",
aggregate_time = "all",
aggregate_time_fun = "mean",
palette = "Reds",
var_label = "Min Temp."
)
# Categorical covariate
plot_map(
data = dengue_MS,
var = "biome_name",
time = "date",
unit = "micro_code",
aggregate_time = "all",
map = map_MS,
map_unit = "code",
palette = "Viridis",
var_label = "Biome"
)
# Case counts by year (log)
dengue_MS |>
plot_map(
var = "dengue_cases",
time = "date",
type = "counts",
unit = "micro_code",
pop = "population",
map = map_MS,
map_unit = "code",
palette = "Reds",
transform = "log10p1"
)
# Case incidence by year, binned
plot_map(
dengue_MS,
var = "dengue_cases",
type = "inc",
time = "date",
unit = "micro_code",
pop = "population",
pt = 1000,
map = map_MS,
map_unit = "code",
bins = 5,
palette = "Viridis"
)