-
Notifications
You must be signed in to change notification settings - Fork 0
/
R Script
59 lines (44 loc) · 2.25 KB
/
R Script
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
## Mapa de la Región de Biobío##
# install.packages("sf")
# install.packages("ggthemes")
library(tidyverse)
library(sf)
library(ggthemes)
library(readxl)
library(dplyr)
#Aquí tienen que poner el directorio específido a su pavada
# Se descarga de esta página: https://www.ine.gob.cl/herramientas/portal-de-mapas/geodatos-abiertos
# Una vez ahí ir a Cartografía > Censo 2017 > División Político Administrativa Y Censal > SHP
# Descargar el archivo zip que se llama: Censo 2017... Comuna
ruta_shapefile <- "C:/Users/Administrador/Downloads/comunas_2017/Comuna_Densid_Superficie.shp"
# Lee el archivo shapefile
datos_sf <- st_read(dsn = ruta_shapefile)
str(datos_sf)
#Mapa de Chilito
ggplot(datos_sf)+geom_sf()
#Región de Bío- Bío
capa_biobio<-filter(datos_sf, REGION== "8" )
ggplot(capa_biobio)+geom_sf()
#Realmente pueden filtrar la región que quieran (mirar el diccionario para ver el número de a región)
ggplot(capa_biobio)+geom_sf(aes(fill=Densidad_) )+
geom_sf_text(data = capa_biobio, aes(label = NOM_COMUNA ), size=1.2)
#Pego mi variable
ruta_excel <- "C:/Users/Administrador/Downloads/comunas_2017/COMUNAS.xlsx"
datos_excel <- read_excel(ruta_excel)
datos_excel$COMUNA <- as.character(datos_excel$COMUNA)
capa_biobio$COMUNA <- as.character(capa_biobio$COMUNA)
capa_biobio_completa <- left_join(capa_biobio, datos_excel, by = "COMUNA")
capa_biobio_completa$COMUNA <- as.numeric(capa_biobio_completa$COMUNA)
#Grafico minería de Carbón en 1940-1950
ggplot(capa_biobio_completa)+geom_sf(aes(fill= factor(Carbón) ) )+
geom_sf_text(data = capa_biobio_completa, aes(label = NOM_COMUNA ), size=1.2)
ggplot(capa_biobio_completa)+geom_sf(aes(fill=factor(Grisu) ) )+
geom_sf_text(data = capa_biobio_completa, aes(label = NOM_COMUNA ), size=1.5)+
theme_minimal()
colores_carbon <- c("#D3D9E6", "#8FC97F", "#51B6C4")
niveles_grisu <- unique(capa_biobio_completa$Grisu) # Obtener los niveles únicos de la variable Carbón
ggplot(capa_biobio_completa) +
geom_sf(aes(fill = factor(Grisu))) +
geom_sf_text(data = capa_biobio_completa, aes(label = NOM_COMUNA), size = 1.5) +
scale_fill_manual(values = setNames(colores_carbon, niveles_grisu)) + # Asignar colores pastel a cada nivel de Carbón
labs(fill = "Grisu") # Etiqueta para la leyenda de colores