Encapsulates the choropleth boilerplate and goes beyond a single style.
Auto-detects the polygon vs sf backend, applies theme_world_map(), and –
for sf – a real projection via ggplot2::coord_sf(). Binned / quantile /
jenks styles are offered because a continuous fill on a skewed indicator
hides almost all the variation; binning is the honest default for
choropleths.
Usage
world_map(
data,
fill,
style = c("continuous", "binned", "quantile", "jenks", "categorical"),
projection = "equal_earth",
palette = NULL,
n_bins = 5,
borders = TRUE,
title = NULL,
legend = NULL,
na_label = "No data",
recenter = NULL
)Arguments
- data
A map-ready frame from
world_data()/join_world()(polygon tibble orsf).- fill
The fill column (unquoted).
- style
"continuous"(default),"binned","quantile","jenks"or"categorical".- projection
For the
sfbackend, any of the projections inworld_geometry():"equal_earth"(default),"robinson","mollweide","natural_earth","plate_carree","mercator","winkel_tripel","eckert4","gall_peters","orthographic","azimuthal_equal_area","north_polar"or"south_polar".- palette
Optional palette name passed to the relevant
ggplot2scale.- n_bins
Number of bins for binned/quantile/jenks styles.
- borders
Draw country borders (default
TRUE).- title, legend
Optional plot title and legend title.
- na_label
Legend label for missing data.
- recenter
Optional central meridian for the
sfbackend.
Examples
# \donttest{
snap <- countryatlas::world_snapshot$countries
if (requireNamespace("maps", quietly = TRUE)) {
mapdf <- attach_geometry(snap, geometry = "polygon")
world_map(mapdf, gdp_per_capita, style = "quantile")
}
# }
