Skip to content

riatelab/mapsf

Repository files navigation

mapsf

CRAN R-CMD-check downloads Codecov test coverage status OpenSSF Best Practices Project Status: Active – The project has reached a stable, usable state and is being actively developed.

Create thematic maps and integrate them into your R workflow.
This package helps you design different cartographic representations such as proportional symbols, choropleths, or typology maps.
It also provides several functions for displaying layout elements that enhance the graphical presentation of maps (e.g., scale bar, north arrow, title, labels).
mapsf maps sf objects on base graphics.

Cheat Sheet & Web Site

Cheat Sheet & Web Site

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:

# A map with a theme and extra margins
mf_theme("sol_dark")
# Plot a choropleth map
mf_map(
  x = mtq, var = "MED", type = "choro",
  breaks = "quantile", nbreaks = 6,
  leg_title = "Median Income\n(euros)", leg_val_rnd = -2,
  expandBB = c(0, 0, 0, .3)
)
# 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")

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.