generated from dieghernan/chulapa-101
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDemoMadrid.R
79 lines (60 loc) · 2.83 KB
/
DemoMadrid.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
67
68
69
70
71
72
73
74
75
76
77
78
79
library(sf)
url <- "https://geoportal.madrid.es/fsdescargas/IDEAM_WBGEOPORTAL/ESTADISTICA/ESTRUCTURA_DEMOGRAFICA/estructura_demografica.zip"
tempzip <- tempfile(fileext = ".zip")
download.file(url, tempzip)
files <- unzip(tempzip, list=TRUE)
unzip(tempzip, exdir = tempdir(), junkpaths = TRUE)
shp_cens <- st_read(file.path(tempdir(),"Estructura_demografica_seccion_censal.shp" ))
shp_barrio <- st_read(file.path(tempdir(),"Estructura_demografica_barrio.shp" ))
shp_dist <- st_read(file.path(tempdir(),"Estructura_demografica_distrito.shp" ))
library(ggplot2)
extr_cens <- ggplot(shp_cens) +
geom_sf(aes(fill=Proporci_3), color=NA) +
geom_sf(data=shp_dist, fill=NA, color="grey5", size=0.1)+
scale_fill_gradientn(colours = hcl.colors(10,"Lajolla"),
labels = function(x) paste0(x,"%"),
name="",
guide = guide_colorsteps(barheight=10,
barwidth=0.6)
) +
theme_void()
ggsave("./assets/img/wiki/PorcExtMadrid2020.svg", width = 7, height = 7)
extr_barr <- ggplot(shp_barrio) +
geom_sf(aes(fill=Proporci_3), color=NA) +
geom_sf(data=shp_dist, fill=NA, color="grey5", size=0.1)+
scale_fill_gradientn(colours = hcl.colors(10,"Lajolla"),
labels = function(x) paste0(x,"%"),
name="",
breaks= seq(0,35,5),
guide = guide_colorsteps(barheight=25,
barwidth=0.6)
) +
theme_void() +
theme(legend.text = element_text(size=20))
extr_barr
ggsave("./assets/img/wiki/PorcExtMadrid2020Barrio.svg", width = 7, height = 7)
ggsave("./assets/img/wiki/PorcExtMadrid2020Barrio.png", width = 7, height = 7)
extr_dist <- ggplot(shp_dist) +
geom_sf(aes(fill=Proporci_3), color=NA) +
geom_sf(data=shp_dist, fill=NA, color="grey5", size=0.1)+
scale_fill_gradientn(colours = hcl.colors(10,"Lajolla"),
labels = function(x) paste0(x,"%"),
breaks = seq(0,25,5),
name="",
guide = guide_colorsteps(barheight=10,
barwidth=0.6)
) +
theme_void()
ggsave("./assets/img/wiki/PorcExtMadrid2020Dist.svg", width = 7, height = 7)
ggplot(shp_dist) +
geom_sf(aes(fill=Densidad), color=NA) +
geom_sf(data=shp_dist, fill=NA, color="grey5", size=0.1)+
scale_fill_gradientn(colours = hcl.colors(10,"Lajolla"),
labels = scales::label_comma(),
name="pop/km2",
breaks = seq(0,350,50),
guide = guide_colorsteps(barheight=10,
barwidth=0.6)
) +
theme_void()
ggsave("./assets/img/wiki/DensMadrid2020Dist.svg", width = 7, height = 7)