forked from flodebarre/covid_vaccination
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testmapGgplot2.R
66 lines (49 loc) · 2.22 KB
/
testmapGgplot2.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Source map data
# https://gadm.org/download_country_v3.html
fra <- readRDS("data/gadm36_FRA_2_sf.rds")
##
# Install packages...
##
#install.packages("rgdal", configure.args = c("--with-proj-lib=/usr/local/lib/", "--with-proj-include=/usr/local/include/"))
#install.packages("sf", configure.args = "--with-proj-lib=/usr/local/lib/")
# install.packages("sf")
# brew update
# brew upgrade
# brew install gdal --HEAD
# WORKED!
# https://github.com/r-spatial/sf/issues/1536#issuecomment-727342736
# Install brew
# /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
# Install the packages:
# brew install pkg-config
# brew install gdal proj geos
# 2.1) Not sure it's necessary ... I included it on terminal.
# export LDFLAGS="-L/usr/local/opt/libpq/lib"
# export CPPFLAGS="-I/usr/local/opt/libpq/include"
# #install.packages("devtools") # Worked
# install.packages("rgeos", repos="http://R-Forge.R-project.org", type="source") # worked
# install.packages("rgdal", repos="http://R-Forge.R-project.org", type="source") # worked
# library(devtools) # Worked
# install_github("r-spatial/sf", configure.args = "--with-proj-lib=/usr/local/lib/") # Worked
###
library("ggplot2")
library("sf")
#install.packages("viridis")
library(viridis)
?chloroLayer
fra.merged <- merge(fra, final.both, by.x = "CC_2", by.y = "departement_residence")
# Bin data
fra.merged$tmp <- as.factor(1*(fra.merged$diffInjRes.1D < -100000) + 1*(fra.merged$diffInjRes.1D < -50000) + 1*(fra.merged$diffInjRes.1D < -20000) + 1*(fra.merged$diffInjRes.1D < 20000) + 1*(fra.merged$diffInjRes.1D < 50000) + 1*(fra.merged$diffInjRes.1D < 100000) + 1*(fra.merged$diffInjRes.1D < 200000))
fra.merged$tmp
library(RColorBrewer)
for(i in dev.list()) dev.off()
fra_map <- ggplot(fra.merged) +
geom_sf(aes(fill = tmp), show.legend = FALSE, color = "white", size = 0.2) +
# enlever l'affichage des coordonnés et de la grille
coord_sf(datum = NA, expand = FALSE) +
# scale_fill_viridis(discrete = TRUE, option = "D") +
# ggtitle("Carte des départements français") +
scale_fill_brewer(palette = "RdBu") +
theme(panel.background = element_blank(),
plot.title = element_text(hjust = 0.5, size = 16))+ theme(legend.position = "bottom")
fra_map