Learn R Programming

mapsf

Create and integrate thematic maps in your R workflow. This package helps to design various cartographic representations such as proportional symbols, choropleth or typology maps. It also offers several functions to display layout elements that improve the graphic presentation of maps (e.g. scale bar, north arrow, title, labels). mapsf maps sf objects on base graphics.

Installation

You can install the released version of mapsf from CRAN with:

install.packages("mapsf")

Alternatively, you can install the development version of mapsf from GitHub (dev branch) with:

remotes::install_github("riatelab/mapsf", ref = "dev")

Usage

This is a basic example which shows how to create a map with mapsf.
The main mapsf function is mf_map().

library(mapsf)
# Import the sample dataset
mtq <- mf_get_mtq()
# Plot the base map
mf_map(x = mtq)
# Plot proportional symbols
mf_map(x = mtq, var = "POP", type = "prop", leg_pos = "topright")
# Plot a map layout
mf_layout(
  title = "Population in Martinique",
  credits = "T. Giraud; Sources: INSEE & IGN, 2018"
)

A more detailed example:

# Export a map with a theme and extra margins
mf_theme("green")
mf_export(
  x = mtq, filename = "mtq.png",
  width = 600, res = 120,
  expandBB = c(0, 0, 0, .3)
)
# Plot a shadow
mf_shadow(mtq, col = "grey10", add = TRUE)
# Plot a choropleth map
mf_map(
  x = mtq, var = "MED", type = "choro",
  pal = "Dark Mint",
  breaks = "quantile",
  nbreaks = 6,
  leg_title = "Median Income\n(euros)",
  leg_val_rnd = -2,
  add = TRUE
)
# Start an inset map
mf_inset_on(x = "worldmap", pos = "right")
# Plot mtq position on a worldmap
mf_worldmap(mtq, col = "#0E3F5C")
# Close the inset
mf_inset_off()
# Plot a title
mf_title("Wealth in Martinique, 2015")
# Plot credits
mf_credits("T. Giraud\nSources: INSEE & IGN, 2018")
# Plot a scale bar
mf_scale(size = 5)
# Plot a north arrow
mf_arrow("topleft")
dev.off()

Resources

  • mapsf, a New Package for Thematic Mapping - useR 2021! Video & Slides - FOSS4G 2021 Video & Slides (EN)
  • Créer des cartes reproductibles avec mapsf - Les lundis de l’Ined - Slides (FR)

Background

mapsf is the successor of cartography. There are no plans for new features or enhancements in cartography, but basic maintenance and support will continue indefinitely. Existing projects that use cartography can safely continue to use cartography. New projects should use mapsf because it is friendlier, lighter and more robust.
See mapsf vignette to migrate from cartography to mapsf.

Alternatives

Community Guidelines

One can contribute to the package through pull requests and report issues or ask questions here. See the CONTRIBUTING.md file for detailed instructions on how to contribute.
This project uses conventional commits and semantic versioning.

Copy Link

Version

Install

install.packages('mapsf')

Monthly Downloads

2,152

Version

0.11.0

License

GPL (>= 3)

Maintainer

Timothée Giraud

Last Published

July 29th, 2024

Functions in mapsf (0.11.0)

mf_get_mtq

Get the 'mtq' dataset
mf_get_links

Get a link layer from a data.frame of links
mf_inset_on

Plot an inset
mf_get_ratio

Get map width and height values
mf_grad

Plot graduated symbols
mf_label

Plot labels
mf_get_pal

Get color palettes
mf_graticule

Plot graticules
mf_init

Initialize a map with a specific extent
mf_get_leg_pos

Get the optimal position of a legend
mf_map

Plot a map
mf_legend

Plot a legend
mf_legend_p

Plot a legend for a proportional symbols map
mf_layout

Plot a map layout
mf_legend_gl

Plot a legend for a graduated lines map
mf_legend_s

Plot a legend for a symbols map
mf_legend_c

Plot a legend for a choropleth map
mf_prop

Plot proportional symbols
mf_legend_pl

Plot a legend for a proportional lines map
mf_shadow

Plot a shadow
mf_scale

Plot a scale bar
mf_theme

Set a theme
mf_symb

Plot symbols
mf_raster

Plot a raster
mf_worldmap

Plot a point on a world map
mf_title

Plot a title
mf_prop_typo

Plot proportional symbols using typology coloration
mf_prop_choro

Plot proportional symbols using choropleth coloration
mf_legend_t

Plot a legend for a typology map
mf_symb_choro

Plot symbols using choropleth coloration
mf_typo

Plot a typology map
mf_choro

Plot a choropleth map
mf_export

Export a map
mf_distr

Plot a distribution
mf_get_breaks

Get class intervals
mf_background

Plot a background image
mf_arrow

Plot a north arrow
mf_credits

Plot credits
mapsf

Package description
mf_annotation

Plot an annotation
mf_base

Plot an sf object