Skip to contents

Creates geographic maps with choropleth fills or point overlays. Used in epidemiology, ecology, geology, economics, and social science. Requires the sf package; rnaturalearth is optional for built-in map data.

Usage

MapPlot(
  data,
  region = NULL,
  value = NULL,
  map_data = NULL,
  map_id = "name",
  type = c("choropleth", "point"),
  point_x = NULL,
  point_y = NULL,
  point_size = 3,
  border_color = "grey50",
  border_width = 0.2,
  na_fill = "grey90",
  color_name = NULL,
  split_by = NULL,
  split_by_sep = "_",
  theme = "theme_ggforge",
  theme_args = list(),
  palette = "Spectral",
  palcolor = NULL,
  alpha = 1,
  aspect.ratio = NULL,
  legend.position = "right",
  legend.direction = "vertical",
  title = NULL,
  subtitle = NULL,
  xlab = NULL,
  ylab = NULL,
  seed = 8525,
  combine = TRUE,
  nrow = NULL,
  ncol = NULL,
  byrow = TRUE,
  axes = NULL,
  axis_titles = NULL,
  guides = NULL,
  design = NULL,
  ...
)

Arguments

data

A data frame containing the data to plot

region

Column matching map region identifiers.

value

Column for fill values (numeric or categorical).

map_data

An sf object with map geometries. If NULL, attempts to use rnaturalearth world map.

map_id

Column in map_data to match against region.

type

Map type: "choropleth" or "point".

point_x, point_y

Column names for point coordinates (type="point").

point_size

Size of map points.

border_color

Color for region borders.

border_width

Width of region borders.

na_fill

Color for regions with no data.

color_name

Legend title.

split_by

Column name(s) to split data into multiple plots

split_by_sep

Separator when concatenating multiple split_by columns

theme

Theme name (string) or theme function

theme_args

List of arguments passed to theme function

palette

Color palette name

palcolor

Custom colors for palette

alpha

Transparency level (0-1)

aspect.ratio

Aspect ratio of plot panel

legend.position

Legend position: "none", "left", "right", "bottom", "top"

legend.direction

Legend direction: "horizontal" or "vertical"

title

Plot title

subtitle

Plot subtitle

xlab

X-axis label

ylab

Y-axis label

seed

Random seed for reproducibility

combine

Whether to combine split plots into one

nrow

Number of rows when combining plots

ncol

Number of columns when combining plots

byrow

Fill combined plots by row

axes

How to handle axes in combined plots ("keep", "collect", "collect_x", "collect_y")

axis_titles

How to handle axis titles in combined plots

guides

How to handle guides in combined plots ("collect", "keep", "auto")

design

Custom layout design for combined plots

...

Additional arguments passed to atomic plotting functions.

Value

A ggplot object or combined plots

See also

Other earth-environmental-plots: ContourPlot(), PolarPlot(), TernaryPlot()

Examples

if (FALSE) { # \dontrun{
# Point map (requires rnaturalearthdata)
cities <- data.frame(
  lon = c(-73.9, -87.6, -118.2, -122.4),
  lat = c(40.7, 41.9, 34.1, 37.8),
  pop = c(8.3, 2.7, 3.9, 0.87)
)
MapPlot(cities, type = "point", point_x = "lon", point_y = "lat",
  value = "pop", color_name = "Population (M)")
} # }