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.

Demo

This 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)

Vignette

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

vignette(topic = "cartography")

Installation

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

Copy Link

Version

Install

install.packages('cartography')

Monthly Downloads

1,094

Version

1.3.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Timothe Giraud

Last Published

June 7th, 2016

Functions in cartography (1.3.0)

cartography

Cartography Package
carto.pal

Build Cartographic Palettes
discLayer

Discontinuities Layer
choroLayer

Choropleth Layer
discretization

Discretization
cartography.colors

Color Palettes
display.carto.pal

Display one Cartographic Palette
countries.spdf

Countries in the European Area
display.carto.all

Display all Cartographic Palettes
coasts.spdf

Coastline of Europe
gradLinkLayer

Graduated Links Layer
gradLinkTypoLayer

Graduated and Colored Links Layer
dotDensityLayer

Dot Density layer
frame.spdf

Frame around Europe
getGridLayer

Build a Regular Grid Layer
getGridData

Compute Data for a Grid Layer
getFigDim

Get Figure Dimensions
getBorders

Extract SpatialPolygonsDataFrame Borders
getLinkLayer

Create a SpatialLinesDataFrame from a Data Frame of Links.
getTiles

Get Tiles from Open Map Servers
legendChoro

Legend for Choropleth Maps
legendCirclesSymbols

Legend for Proportional Circles Maps
propSymbolsTypoLayer

Proportional Symbols Typo Layer
nuts2.df

Nuts2 Dataset
propTrianglesLayer

Double Proportional Triangle Layer
nuts1.spdf

Nuts1 Regions
legendBarsSymbols

Legend for Proportional Bars Maps
layoutLayer

Layout Layer
nuts2.spdf

Nuts2 Regions
nuts3.df

Nuts3 Dataset
smoothLayer

Smooth Layer
tilesLayer

Plot Tiles from Open Map Servers
propLinkLayer

Proportional Links Layer
nuts3.spdf

Nuts3 Regions
labelLayer

Label Layer
twincities

Twin Cities Dataset
graticule.spdf

Graticule around Europe
typoLayer

Typology Layer
legendPropLines

Legend for Proportional Lines Maps
legendGradLines

Legend for Graduated Size Lines Maps
nuts0.spdf

Nuts0 Regions
nuts1.df

Nuts1 Dataset
world.spdf

World Background
legendSquaresSymbols

Legend for Proportional Squares Maps
legendPropTriangles

Legend for Double Proportional Triangles Maps
legendTypo

Legend for Typology Maps
propSymbolsChoroLayer

Proportional and Choropleth Symbols Layer
nuts0.df

Nuts0 Dataset
propSymbolsLayer

Proportional Symbols Layer