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 allows various cartographic representations such as proportional symbols, chroropleth, typology, flows or discontinuities. In addition, it also proposes some useful features like cartographic palettes, layout (scale, north arrow, title...), labels, legends or access to cartographic API to ease the graphic presentation of maps.

cartography uses R base graphics to map spatial information.

Vignette

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

vignette(topic = "cartography")

Blog posts, tutorials

Demo codes in the R graph Gallery (EN)
Create and integrate maps in your R workflow with the cartography package (EN)
Cartographie avec R : le package cartography (FR)
R pour les cartographes (FR)
Comment faire un carton avec R? (FR - How to build inset maps)
Tutoriel - Cartographie avec R (FR)
Cartographie et traitement de l’information géographique avec R (FR)
R pour les cartographes : le package cartography (FR)

Installation

  • Development version on GitHub
require(devtools)
devtools::install_github("Groupe-ElementR/cartography")
  • Stable version on CRAN
install.packages("cartography")

Demo

  • You can access the code used to create the cartographic mix here.

  • The following script creates a map of symbols that are proportional to values of a

first variable and colored to reflect the discretization of a second variable.

library(cartography)
# Load data
data(nuts2006)
# set margins
opar <- par(mar = c(0,0,1.2,0))

# Compute the compound annual growth rate
nuts2.df$cagr <- (((nuts2.df$pop2008 / nuts2.df$pop1999)^(1/9)) - 1) * 100

# Plot a layer with the extent of the EU28 countries with only a background color
plot(nuts0.spdf, border = NA, col = NA, bg = "#A6CAE0")
# Plot non european space
plot(world.spdf, col  = "#E3DEBF", border=NA, add=TRUE)
# Plot Nuts2 regions
plot(nuts2.spdf, col = "grey60",border = "white", lwd=0.4, add=TRUE)

# Set a custom color palette
cols <- carto.pal(pal1 = "blue.pal", n1 = 2, pal2 = "red.pal", n2 = 4)

# Plot symbols with choropleth coloration
propSymbolsChoroLayer(spdf = nuts2.spdf, 
                      df = nuts2.df, 
                      var = "pop2008", #  field in df to plot the symbols sizes
                      inches = 0.1, # set the symbols sizes
                      var2 = "cagr", #  field in df to plot the colors
                      col = cols, # symbols colors
                      breaks = c(-2.43,-1,0,0.5,1,2,3.1), # breaks
                      border = "grey50",  # border colors of the symbols
                      lwd = 0.75, # symbols width
                      legend.var.pos = "topright", # legend position
                      legend.var.values.rnd = -3, # legend value 
                      legend.var.title.txt = "Total Population", # size legend title
                      legend.var.style = "e", # legend type
                      legend.var2.pos = "right", # legend position
                      legend.var2.title.txt = "Compound Annual\nGrowth Rate") # legend title

# layout
layoutLayer(title = "Demographic trends, 1999-2008", coltitle = "black",
            sources = "Eurostat, 2011", scale = NULL,
            author = "cartography", frame ="", col = NA)
par(opar)

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

1.4.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Timothée Giraud

Last Published

December 15th, 2016

Functions in cartography (1.4.1)

carto.pal

Build Cartographic Palettes
display.carto.pal

Display one Cartographic Palette
getLinkLayer

Create a SpatialLinesDataFrame from a Data Frame of Links.
dotDensityLayer

Dot Density layer
getOuterBorders

Extract SpatialPolygonsDataFrame Outer Borders
getBreaks

Discretization
getGridLayer

Build a Regular Grid Layer
getGridData

Compute Data for a Grid Layer
frame.spdf

Frame around Europe
getFigDim

Get Figure Dimensions
getBorders

Extract SpatialPolygonsDataFrame Borders
labelLayer

Label Layer
gradLinkTypoLayer

Graduated and Colored Links Layer
graticule.spdf

Graticule around Europe
legendGradLines

Legend for Graduated Size Lines Maps
legendCirclesSymbols

Legend for Proportional Circles Maps
getTiles

Get Tiles from Open Map Servers
legendBarsSymbols

Legend for Proportional Bars Maps
gradLinkLayer

Graduated Links Layer
layoutLayer

Layout Layer
legendChoro

Legend for Choropleth Maps
legendSquaresSymbols

Legend for Proportional Squares Maps
propSymbolsLayer

Proportional Symbols Layer
propTrianglesLayer

Double Proportional Triangle Layer
north

North Arrow
legendPropTriangles

Legend for Double Proportional Triangles Maps
legendPropLines

Legend for Proportional Lines Maps
propLinkLayer

Proportional Links Layer
propSymbolsTypoLayer

Proportional Symbols Typo Layer
propSymbolsChoroLayer

Proportional and Choropleth Symbols Layer
legendTypo

Legend for Typology Maps
typoLayer

Typology Layer
smoothLayer

Smooth Layer
tilesLayer

Plot Tiles from Open Map Servers
world.spdf

World Background
carto.pal.info

Display the Names of all Cartographic Palettes
discLayer

Discontinuities Layer
cartography

Cartography Package
display.carto.all

Display all Cartographic Palettes
barscale

Scale Bar
cartography.colors

Color Palettes
countries.spdf

Countries in the European Area
choroLayer

Choropleth Layer
coasts.spdf

Coastline of Europe