| plot_map | R Documentation |
Create a choropleth map from census data.
plot_map(
data,
fill_var,
title = NULL,
subtitle = NULL,
legend_title = NULL,
palette = "viridis",
reverse = FALSE,
direction = NULL,
na_color = "grey80",
boundary_year = NULL,
base_layer = TRUE,
show_state_boundaries = FALSE,
state_boundary_color = "black",
state_boundary_width = 0.3,
trans = "identity",
midpoint = NULL,
oob = NULL,
limits = NULL,
breaks = NULL,
labels = NULL,
font_family = NULL,
legend_position = "right"
)
data |
An sf object or data frame with geometry attached via
|
fill_var |
The variable to map to fill color (unquoted or string) |
title |
Optional title for the map |
subtitle |
Optional subtitle for the map |
legend_title |
Title for the legend |
palette |
Color palette. Options include:
|
reverse |
Logical. Reverse the color palette direction? Default FALSE. |
direction |
Numeric. Alternative to reverse: use -1 to reverse, 1 for default. If both reverse and direction are specified, direction takes precedence. |
na_color |
Color for missing values. Default is "grey80" |
boundary_year |
Census year whose state boundaries to draw beneath the
data, keeping India's full claimed extent on the map even where the census
enumerates no districts. Defaults to the |
base_layer |
Logical. Draw India's full state outline beneath the data? Default TRUE |
show_state_boundaries |
Logical. Overlay state boundaries? |
state_boundary_color |
Color for state boundaries. Default is "black" |
state_boundary_width |
Width of state boundary lines. Default is 0.3 |
trans |
Transformation for the color scale (e.g., "log10", "sqrt"). Default is "identity" (no transformation) |
midpoint |
Value to centre a diverging palette on, e.g. |
oob |
How to treat values outside |
limits |
Optional limits for the color scale as c(min, max) |
breaks |
Optional breaks for the legend |
labels |
Optional labels for the legend breaks |
font_family |
Font family for all map text. Default |
legend_position |
One of |
A ggplot2 object
# Calculate ST percentage and attach geometry
st_data <- census_2011_pca |>
dplyr::mutate(st_pct = 100 * st_population / population_total) |>
attach_geometry(2011)
# Create a basic map
plot_map(st_data, st_pct, title = "ST Population %")
# With red-blue palette and state boundaries
plot_map(st_data, st_pct,
title = "ST Population % (2011)",
palette = "red_blue",
show_state_boundaries = TRUE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.