District Location Map of Madre de Dios- Peru Developed in R studio environment I add the R code for your script I hope it will be useful for your Sig projects with R

1 year ago 17 Replies
GC
Gorki Florez Castillo
3 years ago

District Location Map of Madre de Dios- Peru

Developed in R studio environment I add the R code for your script I hope it will be useful for your Sig projects with R

Librerias

#------------------------------------------------------------------------
library(tidyverse)
library(rnaturalearth) #Continentes
library(rnaturalearthdata) #Continentes especifico
library(sf)
library(raster) # Extracion de Peru
library(reticulate)
library(maptools)
library(maps)
library(ggplot2) # Graficos avanzados
library(ggspatial) # Norte
#------------------------------------------------------------------------
world <- ne_countries(scale= "small", returnclass = "sf")# Continentes del mundo
world.SA <- subset(world, continent=="South America") # Sur America

obtener puntos centrales y coordenadas para etiquetar los nombres de los países

world_points<- st_centroid(world) # Centros de cada pais
world_points <- cbind(world, st_coordinates(st_centroid(world$geometry))) #Utilizamos la geometria
Sur_America <- subset(world_points, continent == "South America")

Peru_S <- subset(Sur_America, iso_a3 == "PER") # Seleccionamos por Pais
Peru <- getData('GADM', country='Peru', level=2) #Extracion de Peru
Depa <- st_read("Departamentos.shp") #Departamentos
Dis <- st_read("DistritosMDD.shp") # Distritos de Madre de Dios
Marco_Per = st_as_sfc(st_bbox(Peru))
#------------------------------------------------------------------------

COLORES A DISPOSICION

library(colorspace) #https://awesomeopensource.com/project/EmilHvitfeldt/r-color-palettes
hcl_palettes(plot = TRUE)
q4 <- qualitative_hcl(4, palette = "Dark 3")

library(ghibli)
par(mfrow=c(9,3))
for(i in names(ghibli_palettes)) print(ghibli_palette(i))
col <- ghibli_palettes$PonyoLight

library(cartography) #https://awesomeopensource.com/project/EmilHvitfeldt/r-color-palettes
col1 = carto.pal(pal1 = "pastel.pal", n1 = 20)
#------------------------------------------------------------------------

Grafico Continental

P1 <- ggplot() +
geom_sf(data = Sur_America, fill= NA, lwd=1, color="black",alpha = 1, linetype = 1)+
geom_sf(data = Marco_Per, fill = NA, color = 'black', size = 1.2)+
geom_sf(data=Depa, fill=NA, color="black")+
geom_text(data= Sur_America,aes(x=X, y=Y, label=admin), size = 3,
color = "black", fontface = "bold", check_overlap = FALSE)+
annotation_scale() +
annotation_north_arrow(location="br",which_north="true",style=north_arrow_nautical ())+
theme_classic()+
labs(title = "Mapa de América del Sur",
subtitle="Mapa de Ubicacion",caption="Gorky Florez",x="Longitud",y="Latitud",tag="A)")+
theme(panel.grid.major = element_line(color = gray(.5),linetype = "dashed", size = 0.5))

Grafico Nacional

P2 <- ggplot() +
geom_sf(data = Sur_America, fill= "gray80", lwd=0.8, color="White")+
geom_sf(data = Marco_Per, fill = NA, color = 'black', size = 1.2)+
geom_sf(data=Depa, fill="White", color="black")+
geom_text(data= Sur_America,aes(x=X, y=Y, label=admin), size = 3,
color = "black", fontface = "bold", check_overlap = FALSE)+
annotation_scale() +
annotation_north_arrow(location="br",which_north="true",style=north_arrow_nautical ())+
theme_classic()+
labs(title = "Mapa del Peru",
subtitle="Mapa de Ubicacion",caption="Gorky Florez",x="Longitud",y="Latitud",tag="B)")+
theme(panel.grid.major = element_line(color = gray(.5),linetype = "dashed", size = 0.5))+
coord_sf(xlim = c(-84, -65.24139), ylim = c(-20.49861, 3.59028),expand = FALSE)

Grafico Distrital

P3 <- ggplot() +
geom_sf(data = Sur_America, fill= NA, lwd=0.8, color="black")+
geom_sf(data = Marco_Per, fill = NA, color = 'black', size = 1.2)+
geom_sf(data=Depa, fill=NA, color="black")+
geom_sf(data=Dis, aes(fill = DI_NODIS), show.legend = FALSE)+
scale_fill_manual(values = grey.colors(13, rev = TRUE))+
geom_text(data= Sur_America,aes(x=X, y=Y, label=admin), size = 3,
color = "black", fontface = "bold", check_overlap = FALSE)+
annotation_scale() +
annotation_north_arrow(location="br",which_north="true",style=north_arrow_nautical ())+
theme_classic()+
labs(title = "Mapa Distrital de Madre de Dios",
subtitle="Mapa de Ubicacion",caption="Gorky Florez",x="Longitud",y="Latitud",tag="C)")+
theme(panel.grid.major = element_line(color = gray(.5),linetype = "dashed", size = 0.5))+
coord_sf(xlim = c(-73, -68.24139), ylim = c(-13.49861, -9.59028),expand = FALSE)+
labs(color="Species",fill = "Distritos de Madre de Dios")

Grafico en Barras

P4 <- ggplot(Dis, aes(x = DI_NOCAP, y = Hectares) ) +
geom_col( aes(fill = DI_NOCAP), show.legend = FALSE) +
coord_flip() +
scale_fill_manual(values = grey.colors(13, rev = TRUE))+
labs(color="Species",fill = "Tipo de Clima") +
labs(title = "Plot Bar", subtitle = "Plot Barras de Distritos",
caption = "Gorky Florez",x = "Distritos de Madre de Dios", y="Área Distrital (ha)" ,tag = "D)")+
theme_classic()
#-----------------------------------------------------------------------------------

Exportacion del Mapa

library(gridExtra)
B<-grid.arrange(P1,P2,P3, P4,ncol = 3,layout_matrix = cbind(c(1,1,1), c(2,2,2), c(3,3,4)))

Guargdar en formato PNG

ggsave("Tipo de Clima2.png",plot = B, width = 15,height = 9, dpi=900)
#-----------------------------------------------------------------------------------

362 Likes

Replies

Ba Anders 2 years ago

excelente aporte! Por favor, quisiera contar con tu asesoría. Te escribí al imbox.

0 Likes
Andres Ricardo Lopez 3 years ago

Laura Ortegón Leguizamón mira este mapa esta chido :v

0 Likes
Naim Manriquez 3 years ago

Humberto

0 Likes
Renzo Emanuel Terrones Murga 3 years ago

Jhonsy Silva López

1 Like
Josue Benites Garnique 3 years ago

Akemy Gonzales

0 Likes
Rafael Latorre Consuegra 3 years ago

Maria Victoria Ariña

1 Like
Hector Urquijo 3 years ago

http://bit.ly/mapa_interactivo_vacunacion_covid_19

0 Likes
Andrea Cuesta 3 years ago

LadyMateus Fontecha

1 Like
Jorge Paredes 3 years ago

Gracias

0 Likes
Bryan Andia Llerena 3 years ago

Thanks

0 Likes