Professional Documents
Culture Documents
Beamer Carto
Beamer Carto
Beamer Carto
Thibault LAURENT
thibault.laurent@tse-fr.eu
5 mars 2019
Goals
Introduction
Goals
Example
Softwares
Cartography
Mapping
Goals
Goals of cartography
“Cartography is the art and science of making maps”
I Communicate geographical information graphically.
I The look of a map depends on the needs of the audience and
the point that you aim to convey.
As statisticians, we will try to keep in mind that the spatial data
are associated to observed data :
Variables
Individuals 1 ... p
1 x11 ... x1p
2 x21 ... x2p
.. .. ..
. . ... .
n xn1 ... xnp
Thibault LAURENT TSE, CNRS
Cartography with R
Introduction Cartography Spatial Data with R Mapping
Example
Introduction
Goals
Example
Softwares
Cartography
Mapping
Example
Example
Example
Softwares
Introduction
Goals
Example
Softwares
Cartography
Mapping
Softwares
What is GIS?
Softwares
Example of GIS
GIS can be used for databases management, and its tools are
better suited to some analyses and operations. But for data
analysis, it is preferable to use another software.
Softwares
Why R?
Softwares
General information
I Download presentation, R code (file codes carto.R) and
databases at
http://www.thibault.laurent.free.fr/pedago.html.
I Required packages:
> install.packages(c("cartography", "classInt", "devtools",
"dismo", "ggmap", "GISTools", "lwgeom",
"maptools", "mapview", "osmar",
"raster", "RColorBrewer", "tmaptools",
"rgdal", "rgeos", "scales", "sf",
"tidyverse"))
> devtools::install_github("tidyverse/ggplot2")
> devtools::install_github(repo = 'rCarto/photon')
I Set working directory: indicates the path which contains the
file codes carto.R and folder Donnees:
> setwd("K:/...")
Thibault LAURENT TSE, CNRS
Cartography with R
Introduction Cartography Spatial Data with R Mapping
Softwares
Bibliography
http://www.asdar-book.org/
https://geocompr.robinlovelace.net/
Thibault LAURENT TSE, CNRS
Cartography with R
Introduction Cartography Spatial Data with R Mapping
Softwares
Introduction
Cartography
Choose the shape of earth
Geographic coordinate system
Projected coordinate system
Mapping
Shape of earth
Example of Ellipsoid
I IAG GRS80
a = 6 378 137,0m and
b = 6 356 752,314 140m
I WGS 84
a = 6 378 137,0m and
b = 6 356 752,314 245m
I Clarke 1880
a = 6 378 249,2m and
b = 6 356 515,0m
Today in France
Introduction
Cartography
Choose the shape of earth
Geographic coordinate system
Projected coordinate system
Mapping
Some remarks
100°N
50°N
0°
50°S
100°S
80°N
50°N
70°N
48°N
46°N
60°N
44°N
50°N
42°N
5°W 0° 5°E 10°E 160°W 140°W 120°W 100°W 80°W 60°W 40°W
Introduction
Cartography
Choose the shape of earth
Geographic coordinate system
Projected coordinate system
Mapping
Cylindrical Projections
5400000
50°N
5000000
46°N
44°N
0 200 Km
x=500000m
42°N
4600000
5°W 0° 5°E 10°E −200000 0 200000 600000 1000000
Conic Projections
preserves areas.
5.0e+06
0.0e+00
49°
6600000
46.5°
44°
6200000
Azimuthal Projections
I Azimuthal projections are used often for mapping Polar
Regions. Preserves direction property from the center point of
the projection.
I The flag of the United Nations contains an example of a polar
azimuthal equidistant projection.
1e+07
0e+00
−1e+07
WGS84 Long/Lat
2e+06
100°S 90°S 80°S 70°S 60°S 50°S
1e+06
0e+00
−2e+06
0 500 Km
150°W 100°W 50°W 0° 50°E 100°E 150°E −3e+06 −1e+06 0e+00 1e+06 2e+06 3e+06
Summary
General information
I Coordinate Reference Systems (CRS) = Datum + Projection.
I Natural Earth : http://www.naturalearthdata.com/
I GADM database of Global Administrative Areas:
http://www.gadm.org/
I French administrative boundaries and other data (roads,
rivers, altitude, etc.):
http://professionnels.ign.fr/donnees
I The list of the CRS used in the World:
http://www.spatialreference.org/
I How to find a CRS with R:
> EPSG <- make_EPSG()
> EPSG[grep("France", EPSG[,"note"]),]
Introduction
Cartography
Mapping
{"type": "FeatureCollection",
"features": [
{"type": "Feature",
"properties": {
"name": "Van Dorn Street",
"marker-color": "#0000ff",
"marker-symbol": "rail-metro",
"line": "blue"},
"geometry": {
"type": "Point",
"coordinates": [
-77.12911152370515,
38.79930767201779
]}
}]
}
Remark: rgdal and maptools use Spatial class object. raster uses a
different class of object. Some links exist between the 2 classes.
raster is more powerful for image treatment functions.
Introduction
Cartography
Mapping
The sp class
4 different subclasses of Spatial objects (see
vignette("intro sp")):
I SpatialPolygons: spatial unit is represented by a polygon
(country, region, city, etc).
I SpatialPoints: spatial unit is represented by a point
(earthquake, etc).
I SpatialLines: spatial unit is represented by a line (fault,
“failles sismiques”).
I SpatialGrids: spatial unit is represented by a cell (Satellite
imagery). A grid must be defined by using a reference point,
the width of the cell and the number of row/column.
NB: when a spatial unit is associated to a data.frame, we get
SpatialXXXDataFrame object.
Thibault LAURENT TSE, CNRS
Cartography with R
Introduction Cartography Spatial Data with R Mapping
The sf class
Maghreb countries
Maghreb countries
With sf package:
1. create the new ID variable:
> maghreb_sf$NOM_2 <- c("Algeria",
"Morocco", "Libya", "Mauritania", "Tunisia", "Morocco")
2. Use the dplyr syntax:
> library(tidyverse)
> maghreb2_sf <- maghreb_sf %>%
group_by(NOM = NOM_2) %>%
summarise()
3. Add a new variable :
> maghreb2_sf$pib <- c(7300, 5200, 11900, 2100, 9700)
Tunisia : 9700
Mauritania : 2100
Source : CIA
35°N
Tunisia : 9700
30°N
Morocco : 2100
Algeria : 7300
Y
15°N
20°W 10°W 0° 10°E 20°E 30°E 40°E
X
CRS conversion
Spatial overlay
45°N
Magnitude
8
40°N
35°N
30°N
45°N
40°N
35°N
30°N
Thibault LAURENT TSE, CNRS
125°E 130°E 135°E 140°E 145°E
Cartography with R
Introduction Cartography Spatial Data with R Mapping
Introduction
Cartography
Mapping
Image resolution
We would like to decrease the image resolution. Actually, the
number of cells is :
> dim(suneu.fr)
[1] 117 172 1
43.614
43.610
lat
Arsenal
43.606
Manu
43.602
lon
Introduction
Cartography
Mapping
Representing a categorical variable
Representing a numeric variable
Exercice
"blue","green") Aust
Cent
East
North
West
Introduction
Cartography
Mapping
Representing a categorical variable
Representing a numeric variable
Exercice
I The equal style divides the range of the variable into n parts.
I The quantile style provides quantile breaks; arguments to
quantile may be passed through ....
I The kmeans style uses kmeans to generate the breaks.
I The jenks style has been imported from Jenks’ Basic code,
and has been checked for consistency with ArcView, ArcGIS,
and MapInfo.
Application
> require("RColorBrewer")
> plotclr <- brewer.pal(5,"Blues")
equal quantile
> pal1 <- plotclr[c(1,5)]
0.8
0.8
> opar <- par(mfrow=c(2,2))
Fn(x)
Fn(x)
0.4
0.4
> plot(classIntervals(pib,5,"equal"),
0.0
0.0
pal=pal1, main="equal") 0 5000 15000 25000 0 5000 15000 25000
x x
> plot(classIntervals(pib,5,"quantile"),
K−means Jenks
pal=pal1, main="quantile")
0.8
0.8
> plot(classIntervals(pib,5,"kmeans"),
Fn(x)
Fn(x)
0.4
0.4
pal=pal1, main="K-means")
0.0
0.0
> plot(classIntervals(pib,5,"jenks"), 0 5000 15000 25000 0 5000 15000 25000
x x
pal=pal1, main="Jenks")
> par(opar)
Choropleth map
Plotting :
> ind=findInterval(pib, bk, all.inside=TRUE)
> plot(africa, col=plotclr[ind])
> decoup <- c("<=1500","]1500;3850]",
"]3850;10500]","]10500;21550]",">21550") GDP
> SpatialPolygonsRescale(layout.north.arrow(1),
offset = c(50,-30), scale = 5, plot.grid=F)
> title("GDP per inhabitant")
Package cartography
I package cartography by T.
Giraud (2015). See tutorial: GDP in Africa
pib
http://wukan.ums-riate. 26500
8886
4429
2100
1629
fr/RUSS/RUSS_2016/. 1286
843
400
> library("cartography")
> choroLayer(spdf = africa, var = "pib",
legend.pos = "topleft")
> layoutLayer(title = "GDP in Africa", CIA
var="pib" )
Iron
Bauxite
● Coal
●
●
● ● ● ● ●
●
●●
●
●
● ●
●
●
● ●
●
●
●
Exercice
Introduction
Cartography
Mapping
Representing a categorical variable
Representing a numeric variable
Exercice
Exercice
Exercice
Exercice
Exercice
nb_bornette_pop
0.04
0.023
0.015
0.012
0.01
0.009
0.007
0.004
no data
Toulouse Metropole