Capitales de los distritos peruanos

Column

Líneas de contorno

Column

Áreas de contorno

---
title: "Día 8 #30díasdegráficos (gráfico de contornos). Capitales de los distritos en Perú (ESP)"
author: "Rubén F. Bustillo"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    source_code: embed
    vertical_layout: fill
    theme: simplex
    
---

```{r setup, include=FALSE}


# PACKAGES / LIBRARIES:

library(tidyverse)
library(plotly)
library(readxl)
library(leaflet)
library(sf)
library(raster)
library(ggiraph)
library(scales)
library(RColorBrewer)

options(scipen=999)

alturas <- read_excel("C:/Users/Usuario/Desktop/r_que_r/r_que_r/content/datasets/alturas.xlsx")

PER_1 <- getData("GADM", country ="PE", level =1)

PERU_1_df <-broom::tidy(PER_1, region = "NAME_1")


```



Capitales de los distritos peruanos
===========================================================================

Column {data-width=500}
---------------------------------------------------------------------------


### Líneas de contorno 

```{r, out.width="100%"}

ggplot(alturas, aes(x= LONGITUD, y = LATITUD, color = ALTITUD)) +
  labs(title = "Peru: Capitales de Distrito",
       subtitle = "",
       caption = "Fuente: CEPLAN",
       fill = NULL) +
  geom_polygon(data = PERU_1_df,
               aes(x = long, y = lat, group = group),
               fill = "orange",
               color = "grey",
               size = 0.2,
               alpha = 0.2) +
  geom_point(data = alturas,
                         aes(x =LONGITUD, y = LATITUD),
                         size = 0.5) +
  scale_color_gradient(low="forestgreen", high = "indianred",
                       labels = scales::comma,
                       name = "Altitud (msnm)") +
  stat_density2d(color = "grey50")+
  coord_map() +
  theme_void()+
  theme(
    axis.line = element_blank(),
    axis.text = element_blank(),
    axis.title = element_blank(),
    axis.ticks = element_blank(),
    plot.background = element_rect(fill = "snow", color = NA),
    panel.background = element_rect(fill= "snow", color = NA),
    plot.title = element_text(size = 11, hjust = 0.5),
    plot.subtitle = element_text(size = 10, hjust = 0.5),
    plot.caption = element_text(size = 7, hjust = 1),
    legend.title = element_text(color = "grey40", size = 7),
    legend.text = element_text(color = "grey40", size = 6, hjust = 0),
    legend.position = c(0, 0.2),
    plot.margin = unit(c(0.5, 3, 1, 2), "cm"))



```


Column {data-width=500}
---------------------------------------------------------------------------


### Áreas de contorno

```{r, out.width="100%"}

ggplot(alturas, aes(x= LONGITUD, y = LATITUD, color = ALTITUD)) +
  labs(title = "Peru: Capitales de Distrito",
       subtitle = " ",
       caption = "Fuente: CEPLAN",
       fill = NULL) +
  geom_polygon(data = PERU_1_df,
               aes(x = long, y = lat, group = group),
               fill = "orange",
               color = "grey",
               size = 0.2,
               alpha = 0.2) +
  geom_point(data = alturas,
                         aes(x =LONGITUD, y = LATITUD),
                         size = 0.5) +
  scale_color_gradient(low="forestgreen", high = "indianred",
                       labels = scales::comma,
                       name = "Altitud (msnm)") +
  stat_density2d(aes(fill = ..level..), alpha = 0.3, geom = "polygon")+
  scale_fill_gradientn(colours=rev(brewer.pal(6,"Spectral")),
                       name = "Densidad")+
  coord_map() +
  theme_void()+
  theme(
    axis.line = element_blank(),
    axis.text = element_blank(),
    axis.title = element_blank(),
    axis.ticks = element_blank(),
    plot.background = element_rect(fill = "snow", color = NA),
    panel.background = element_rect(fill= "snow", color = NA),
    plot.title = element_text(size = 11, hjust = 0.5),
    plot.subtitle = element_text(size = 10, hjust = 0.5),
    plot.caption = element_text(size = 7, hjust = 1),
    legend.title = element_text(color = "grey40", size = 7),
    legend.text = element_text(color = "grey40", size = 6, hjust = 0),
    legend.position = c(0, 0.2),
    plot.margin = unit(c(0.5, 3, 1, 2), "cm")) 


```