Learn R Programming

⚠️There's a newer version (3.1.4) of this package.Take me there.

cartography

Create and integrate maps in your R workflow!

This package helps to design cartographic representations such as proportional symbols, choropleth, typology, flows or discontinuities maps. It also offers several features that improve the graphic presentation of maps, for instance, map palettes, layout elements (scale, north arrow, title...), labels or legends.

Cheat Sheet

The cheat sheet displays a quick overview of cartography's main features.

Vignette

The vignette contains commented scripts on how to build various types of maps with cartography:

Other Resources

Demo

The following script creates a map of symbols that are proportional to values of a first variable and colored to reflect the classification of a second variable.

library(sf)
library(cartography)
# path to the geopackage file embedded in cartography
path_to_file <- system.file("gpkg/mtq.gpkg", package="cartography")
# import to an sf object
mtq <- st_read(dsn = path_to_file, quiet = TRUE)

########## Draft Map
# Plot the municipalities
plot(st_geometry(mtq))
# Plot symbols with choropleth coloration (population & median income)
propSymbolsChoroLayer(x = mtq, var = "POP", var2 = "MED")
# Add a layout
title(main = "Population & Wealth in Martinique, 2015", 
      sub = "Sources: Insee and IGN - 2018")

########## Final Map
# Set figure margins
opar <- par(mar = c(0,0,1.2,0))
# Plot the municipalities
plot(st_geometry(mtq), col="darkseagreen3", border="darkseagreen4",  
     bg = "lightblue1", lwd = 0.5)
# Plot symbols with choropleth coloration
propSymbolsChoroLayer(x = mtq, var = "POP", inches = 0.4, border = "grey50",
                      lwd = 1, legend.var.pos = "topright", 
                      legend.var.title.txt = "Population",
                      var2 = "MED", method = "equal", nclass = 4, 
                      col = carto.pal(pal1 = "sand.pal", n1 = 4),
                      legend.var2.values.rnd = -2,  legend.var2.pos = "left", 
                      legend.var2.title.txt = "Median Income\n(in euros)") 
# Plot a layout
layoutLayer(title="Population & Wealth in Martinique, 2015", 
            author = "cartography 2.1.3", 
            sources = "Sources: Insee and IGN - 2018", 
            scale = 5, tabtitle = TRUE, frame = FALSE)
# Plot a north arrow
north(pos = "topleft")
# restore graphics parameters
par(opar)

Installation

  • Development version on GitHub
require(remotes)
install_github("riatelab/cartography")
  • Stable version on CRAN
install.packages("cartography")

Alternatives Packages

Community Guidelines

One can contribute to the package through pull requests and report issues or ask questions here.

Copy Link

Version

Install

install.packages('cartography')

Monthly Downloads

1,094

Version

2.4.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Timothée Giraud

Last Published

April 20th, 2020

Functions in cartography (2.4.1)

discLayer

Discontinuities Layer
getBorders

Extract Polygons Borders
choroLayer

Choropleth Layer
coasts.spdf

Coastline of Europe
dotDensityLayer

Dot Density Layer
barscale

Scale Bar
carto.pal

Build Cartographic Palettes
frame.spdf

Frame around Europe
cartography

Cartography Package
getGridLayer

Build a Regular Grid Layer
legendGradLines

Legend for Graduated Size Lines Maps
countries.spdf

Countries in the European Area
gradLinkLayer

Graduated Links Layer
ghostLayer

Plot a Ghost Layer
gradLinkTypoLayer

Graduated and Colored Links Layer
getBreaks

Classification
graticule.spdf

Graticule around Europe
getGridData

Compute Data for a Grid Layer
getPngLayer

.png Layer
getFigDim

Get Figure Dimensions
legendCirclesSymbols

Legend for Proportional Circles Maps
propSymbolsLayer

Proportional Symbols Layer
legendChoro

Legend for Choropleth Maps
getTiles

Get Tiles from Open Map Servers
legendTypo

Legend for Typology Maps
legendSquaresSymbols

Legend for Proportional Squares Maps
getLinkLayer

Create a Links Layer from a Data Frame of Links.
getPencilLayer

Pencil Layer
hatchedLayer

Hatched Layer
legendHatched

Legend for Hatched Maps
nuts1.df

Nuts1 Dataset
legendWaffle

Legend for Typology Maps
north

North Arrow
nuts2.spdf

Nuts2 Regions
tilesLayer

Plot a Raster Object
propSymbolsTypoLayer

Proportional Symbols Typo Layer
wordcloudLayer

Wordcloud Layer
nuts2.df

Nuts2 Dataset
labelLayer

Label Layer
legendPropLines

Legend for Proportional Lines Maps
propTrianglesLayer

Double Proportional Triangle Layer
layoutLayer

Layout Layer
legendPropTriangles

Legend for Double Proportional Triangles Maps
world.spdf

World Background
legendBarsSymbols

Legend for Proportional Bars Maps
smoothLayer

Smooth Layer
nuts1.spdf

Nuts1 Regions
twincities.df

Twin Cities Dataset
waffleLayer

Waffle Layer
propLinkLayer

Proportional Links Layer
typoLayer

Typology Layer
nuts0.spdf

Nuts0 Regions
propSymbolsChoroLayer

Proportional and Choropleth Symbols Layer
nuts0.df

Nuts0 Dataset
nuts3.df

Nuts3 Dataset
nuts3.spdf

Nuts3 Regions