---
title: "Peru"
author: "Rubén F. Bustillo"
output:
flexdashboard::flex_dashboard:
storyboard: true
orientation: columns
source_code: embed
vertical_layout: fill
theme: paper
---
```{r setup, include=FALSE}
# PACKAGES / LIBRARIES:
library(flexdashboard)
library(tidyverse)
library(plotly)
library(highcharter)
library(readxl)
```
Regions GVA
===========================================================================
Column {data-width=200}
---------------------------------------------------------------------------
###
\
Column
---------------------------------------------------------------------------
### Gross Value Added by region (% of total GVA), 2018
```{r}
options(scipen=999)
peru_mapa_vab2016 <- read_excel("C:/Users/Usuario/Desktop/r_que_r/r_que_r/content/datasets/peru_mapa_vab2018.xlsx")
peru_mapa_vab2016_A <- peru_mapa_vab2016 %>%
mutate(name = if_else(name == "Áncash", "Ancash", name)) %>%
mutate("woe-name" = name)
peru_mapa_vab2016_A$pob_2016_perc <- formatC(peru_mapa_vab2016_A$pob_2016_perc, digits = 3)
peru_mapa_vab2016_A$Vab_perc_16 <- formatC(peru_mapa_vab2016_A$Vab_perc_16, digits = 3)
hcmap(map = "countries/pe/pe-all", data = peru_mapa_vab2016_A,
joinBy = "woe-name", value = "vab_2016") %>%
hc_colorAxis(stops = color_stops()) %>%
hc_mapNavigation(enabled = TRUE) %>%
hc_title(text = "Gross Value Added by region, 2016") %>%
hc_subtitle(text = "In constant 2007 PEN thousands") %>%
hc_tooltip(pointFormat = "
Population: {point.pob_2016}
Pop (%): {point.pob_2016_perc}
GVA: {point.vab_2016}
GVA (%): {point.Vab_perc_16}",
table = TRUE) %>%
hc_credits(enabled = TRUE,
text = "Source: INEI")
```
Column
---------------------------------------------------------------------------
### Gross Value Added by region (log scale), 2018. (in constant 2007 PEN thousands)
```{r}
peru_mapa_vab2016_B <- read_excel("C:/Users/Usuario/Desktop/r_que_r/r_que_r/content/datasets/peru_mapa_vab2018.xlsx")
peru_mapa_vab2016_B %>%
arrange(vab_2016) %>%
mutate(name = factor(name, levels = name)) %>%
plotly::plot_ly(x = ~ vab_2016,
y = ~ name,
type = 'bar',
text = ~ vab_2016,
textposition = 'auto',
marker = list (color = c('mediumseagreen', 'mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen', 'yellow'))) %>%
plotly::layout(title = "",
xaxis = list(type = "log", title = ""),
yaxis = list(title = "")) %>%
plotly::layout(annotations = list(x = 1 , y = -0.05, text = "Source: INEI | The region of Lima (Lima) does not include Lima Province or Callao (Lima Metropolitana) ",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=0,
font=list(size=10, color="darkgrey")))
```
Regions GVApc
===========================================================================
Column {data-width=200}
---------------------------------------------------------------------------
###
\
Column
---------------------------------------------------------------------------
### Gross Value Added by region (% of total GVA), 2018
```{r}
options(scipen=999)
peru_mapa_vab2016 <- read_excel("C:/Users/Usuario/Desktop/r_que_r/r_que_r/content/datasets/peru_mapa_vab2018.xlsx")
peru_mapa_vab2016_A <- peru_mapa_vab2016 %>%
mutate(name = if_else(name == "Áncash", "Ancash", name)) %>%
mutate("woe-name" = name)
peru_mapa_vab2016_A$vabpc_2016 <- as.numeric(formatC(peru_mapa_vab2016$vabpc_2016, digits = 6))
hcmap(map = "countries/pe/pe-all", data = peru_mapa_vab2016_A,
joinBy = "woe-name", value = "vabpc_2016") %>%
hc_colorAxis(stops = color_stops()) %>%
hc_mapNavigation(enabled = TRUE) %>%
hc_title(text = "Gross Value Added per cápita by region, 2016") %>%
hc_subtitle(text = "In constant 2007 PEN thousands") %>%
hc_tooltip(pointFormat = "
Population: {point.pob_2016}
Pop (%): {point.pob_2016_perc}
GVA pc: {point.vabpc_2016}",
table = TRUE) %>%
hc_credits(enabled = TRUE,
text = "Source: INEI")
```
Column
---------------------------------------------------------------------------
### Gross Value Added by region (log scale), 2018. (in constant 2007 PEN thousands)
```{r}
peru_mapa_vab2016_A %>%
arrange(vabpc_2016) %>%
mutate(name = factor(name, levels = name)) %>%
plotly::plot_ly(x = ~ vabpc_2016,
y = ~ name,
type = 'bar',
text = ~ vabpc_2016,
textposition = 'auto',
marker = list (color = c('mediumseagreen', 'mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen','mediumseagreen', 'yellow'))) %>%
plotly::layout(title = "",
xaxis = list(type = "log", title = ""),
yaxis = list(title = "")) %>%
plotly::layout(annotations = list(x = 1 , y = -0.05, text = "Source: INEI | The region of Lima (Lima) does not include Lima Province or Callao (Lima Metropolitana) ",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=0,
font=list(size=10, color="darkgrey")))
```
Regions GVApc
=============================================================================================
Row {.tabset .tabset-fade}
-------------------------------------------------------------
### Per year
```{r, out.width="100%"}
peru_tabla <- read_excel("C:/Users/Usuario/Desktop/r_que_r/r_que_r/content/datasets/peru_tabla.xlsx")
peru_t2 <- peru_tabla %>%
select(id, Year, VABpc_07) %>%
spread(Year, VABpc_07)
fig <- plot_ly(type = "box")
fig <- fig %>% add_boxplot(y = peru_t2$'1995', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "1995")
fig <- fig %>% add_boxplot(y = peru_t2$'1996', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "1996")
fig <- fig %>% add_boxplot(y = peru_t2$'1997', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "1997")
fig <- fig %>% add_boxplot(y = peru_t2$'1998', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "1998")
fig <- fig %>% add_boxplot(y = peru_t2$'1999', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "1999")
fig <- fig %>% add_boxplot(y = peru_t2$'2000', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "2000")
fig <- fig %>% add_boxplot(y = peru_t2$'2001', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "2001")
fig <- fig %>% add_boxplot(y = peru_t2$'2002', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "2002")
fig <- fig %>% add_boxplot(y = peru_t2$'2003', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "2003")
fig <- fig %>% add_boxplot(y = peru_t2$'2004', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "2004")
fig <- fig %>% add_boxplot(y = peru_t2$'2005', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "2005")
fig <- fig %>% add_boxplot(y = peru_t2$'2006', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "2006")
fig <- fig %>% add_boxplot(y = peru_t2$'2007', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "2007")
fig <- fig %>% add_boxplot(y = peru_t2$'2008', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "2008")
fig <- fig %>% add_boxplot(y = peru_t2$'2009', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "2009")
fig <- fig %>% add_boxplot(y = peru_t2$'2010', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "2010")
fig <- fig %>% add_boxplot(y = peru_t2$'2011', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "2011")
fig <- fig %>% add_boxplot(y = peru_t2$'2012', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "2012")
fig <- fig %>% add_boxplot(y = peru_t2$'2013', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "2013")
fig <- fig %>% add_boxplot(y = peru_t2$'2014', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "2014")
fig <- fig %>% add_boxplot(y = peru_t2$'2015', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "2015")
fig <- fig %>% add_boxplot(y = peru_t2$'2016', jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "2016")
fig <- fig %>% layout(title = "GVA per capita by year")
fig
```
### Per region
```{r}
peru_t3 <- peru_tabla %>%
select(id, Year, VABpc_07) %>%
spread(id, VABpc_07)
fig <- plot_ly(type = "box")
fig <- fig %>% add_boxplot(y = peru_t3$AMA, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "AMA")
fig <- fig %>% add_boxplot(y = peru_t3$ANC, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "ANC")
fig <- fig %>% add_boxplot(y = peru_t3$APU, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "APU")
fig <- fig %>% add_boxplot(y = peru_t3$ARE, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "ARE")
fig <- fig %>% add_boxplot(y = peru_t3$AYA, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "AYA")
fig <- fig %>% add_boxplot(y = peru_t3$CAJ, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "CAJ")
fig <- fig %>% add_boxplot(y = peru_t3$CUS, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "CUS")
fig <- fig %>% add_boxplot(y = peru_t3$HUA, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "HUA")
fig <- fig %>% add_boxplot(y = peru_t3$HUAC, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "HUAC")
fig <- fig %>% add_boxplot(y = peru_t3$ICA, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "ICA")
fig <- fig %>% add_boxplot(y = peru_t3$JUN, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "JUN")
fig <- fig %>% add_boxplot(y = peru_t3$LAM, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "LAM")
fig <- fig %>% add_boxplot(y = peru_t3$LIM, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "LIM")
fig <- fig %>% add_boxplot(y = peru_t3$LLIB, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "LLIB")
fig <- fig %>% add_boxplot(y = peru_t3$LOR, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "LOR")
fig <- fig %>% add_boxplot(y = peru_t3$MDD, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "MDD")
fig <- fig %>% add_boxplot(y = peru_t3$MOQ, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "MOQ")
fig <- fig %>% add_boxplot(y = peru_t3$PAS, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "PAS")
fig <- fig %>% add_boxplot(y = peru_t3$PIU, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "PIU")
fig <- fig %>% add_boxplot(y = peru_t3$PUN, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "PUN")
fig <- fig %>% add_boxplot(y = peru_t3$SMA, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "SMA")
fig <- fig %>% add_boxplot(y = peru_t3$TAC, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "TAC")
fig <- fig %>% add_boxplot(y = peru_t3$TUM, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "TUM")
fig <- fig %>% add_boxplot(y = peru_t3$UCA, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "UCA")
fig <- fig %>% add_boxplot(y = peru_t3$PE, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "PERU")
fig <- fig %>% layout(title = "GVA per capita by region")
fig
```
### extra 1
```{r}
hcboxplot(x=peru_tabla$VABpc_07, var= peru_tabla$Year,
name = "Info")%>%
hc_chart(type = "column")
```
### extra 2 (without MOQ)
```{r}
hcboxplot(x=peru_tabla$VABpc_07, var= peru_tabla$Year,
outlier= FALSE)%>%
hc_chart(type = "column")
```
### extra 3
```{r}
hcboxplot(x=peru_tabla$VABpc_07, var= peru_tabla$Region) %>%
hc_chart(type = "column")
```
Ec. Structure
============================================================================
Column {data-width=400}
---------------------------------------------------------------------------
### Gross Value Added by region (% of total GVA), 2016
```{r}
Peru_vab_sectores <- read_excel("C:/Users/Usuario/Desktop/r_que_r/r_que_r/content/datasets/Peru_vab_sectores_2016.xlsx")
names(Peru_vab_sectores) = c("Regions", "AGR", "PES", "EXT", "MAN", "ELEC", "CONS", "COM", "TRANS", "REST", "TELEC", "ADPUB", "OS")
x<-Peru_vab_sectores %>%
group_by(Regions) %>%
mutate(total= AGR + PES + EXT + MAN + ELEC + CONS + COM + TRANS + REST + TELEC + ADPUB + OS) %>%
arrange(total) %>%
ungroup()
x$Regions = factor(x$Regions, levels = x$Regions)
plotly::plot_ly(data = x,
y = ~ Regions,
x = ~ AGR,
orientation = 'h',
name = 'Agriculture, Livestock, Hunting and Forestry',
type = 'bar') %>%
plotly::add_trace( x = ~ PES,
name = "Fishing and Aquaculture") %>%
plotly::add_trace( x = ~ EXT,
name = "Extraction of Minerals, Gas and Oil") %>%
plotly::add_trace( x = ~ MAN,
name = "Manufacturing") %>%
plotly::add_trace( x = ~ ELEC,
name = "Electricity, Gas and Water") %>%
plotly::add_trace( x = ~ CONS,
name = "Construction") %>%
plotly::add_trace( x = ~ COM,
name = "Commerce") %>%
plotly::add_trace( x = ~ TRANS,
name = "Transportation, Storage, Mail and Messaging") %>%
plotly::add_trace( x = ~ REST,
name = "Accommodation and Restaurants") %>%
plotly::add_trace( x = ~ TELEC,
name = "Telecommunications and Other Information Services") %>%
plotly::add_trace( x = ~ ADPUB,
name = "Public Administration and Defence") %>%
plotly::add_trace( x = ~ OS,
name = "Other Services") %>%
plotly::layout(title = " Gross Value Added by region and sector, 2016 \n (constant 2007 PEN thousands)",
barmode = 'stack',
legend = list(x = 0.3, y = 0.5),
yaxis = list(title = ""),
xaxis = list(title = "Source: INEI | Lima does not include Callao or Lima Province"),
hovermode = "compare",
margin = list(
l = 20,
r = 10,
b = 10,
t = 80,
pad = 2
))
```
Column
-----------------------------------------------------------------------------
### SECTORAL PARTICIPATION OVER TOTAL GVA (%)
```{r}
y <-Peru_vab_sectores %>%
group_by(Regions) %>%
mutate(total= AGR + PES + EXT + MAN + ELEC + CONS + COM + TRANS + REST + TELEC + ADPUB + OS) %>%
arrange(total) %>%
mutate(AGR_per = (AGR / total)*100) %>%
mutate(PES_per = (PES / total)*100) %>%
mutate(EXT_per = (EXT / total)*100) %>%
mutate(MAN_per = (MAN / total)*100) %>%
mutate(ELEC_per = (ELEC / total)*100) %>%
mutate(CONS_per = (CONS / total)*100) %>%
mutate(COM_per = (COM / total)*100) %>%
mutate(TRANS_per = (TRANS / total)*100)%>%
mutate(REST_per = (REST / total)*100) %>%
mutate(TELEC_per = (TELEC / total)*100) %>%
mutate(ADPUB_per = (ADPUB / total)*100) %>%
mutate(OS_per = (OS / total)*100) %>%
ungroup()
y$Regions = factor(y$Regions, levels = y$Regions)
y$AGR_per <- format(y$AGR_per, digits = 3)
#y$PES_per <- format(y$PES_per, digits = 2)
y$EXT_per <- format(y$EXT_per, digits = 3)
y$MAN_per <- format(y$MAN_per, digits = 3)
y$ELEC_per <- format(y$ELEC_per, digits = 3)
y$CONS_per <- format(y$CONS_per, digits = 3)
y$COM_per <- format(y$COM_per, digits = 3)
y$TRANS_per <- format(y$TRANS_per, digits = 3)
y$REST_per <- format(y$REST_per, digits = 3)
y$TELEC_per <- format(y$TELEC_per, digits = 3)
y$ADPUB_per <- format(y$ADPUB_per, digits = 3)
y$OS_per <- format(y$OS_per, digits = 3)
plotly::plot_ly(data = y,
y = ~ Regions,
x = ~ AGR_per,
orientation = 'h',
name = 'Agriculture, Livestock, Hunting and Forestry',
type = 'bar') %>%
plotly::add_trace( x = ~ PES_per,
name = "Fishing and Aquaculture",
text = ~ "") %>%
plotly::add_trace( x = ~ EXT_per,
name = "Extraction of Minerals, Gas and Oil",
text = ~ "") %>%
plotly::add_trace( x = ~ MAN_per,
name = "Manufacturing",
text = ~ "") %>%
plotly::add_trace( x = ~ ELEC_per,
name = "Electricity, Gas and Water",
text = ~ "") %>%
plotly::add_trace( x = ~ CONS_per,
name = "Construction",
text = ~ "") %>%
plotly::add_trace( x = ~ COM_per,
name = "Commerce",
text = ~ "") %>%
plotly::add_trace( x = ~ TRANS_per,
name = "Transportation, Storage, Mail and Messaging",
text = ~ "") %>%
plotly::add_trace( x = ~ REST_per,
name = "Accommodation and Restaurants",
text = ~ "") %>%
plotly::add_trace( x = ~ TELEC_per,
name = "Telecommunications and Other Information Services",
text = ~ "") %>%
plotly::add_trace( x = ~ ADPUB_per,
name = "Public Administration and Defence",
text = ~ "") %>%
plotly::add_trace( x = ~ OS_per,
name = "Other Services",
text = ~ "") %>%
plotly::layout(title = " Gross Value Added by region and sector, 2016 \n (% of total GVA)",
barmode = 'stack',
legend = list(x = 1, y = 0.5),
yaxis = list(title = ""),
xaxis = list(title = "Source: INEI | Lima does not include Callao en Lima Province"),
hovermode = "compare",
margin = list(
l = 20,
r = 0,
b = 10,
t = 80,
pad = 2
))
```
Treemap
=========================================================================
Row {.tabset .tabset-fade}
-------------------------------------------------------------
### Sectoral Level
```{r include=FALSE}
Peru_vab_sectores <- read_excel("C:/Users/Usuario/Desktop/r_que_r/r_que_r/content/datasets/Peru_vab_sectores_2016.xlsx")
Peru_sectores <- Peru_vab_sectores %>%
gather(key = "sector", value = "vab", 2:13)
library(treemap)
tree_sectores <- treemap(
Peru_sectores,
index=c("sector","Regions"),
vSize="vab",
title = "GVA, economic sector and region, 2016 ",
vColor="sector",
type="index",
force.print.labels = F,
border.col = c("black", "white"),
border.lwds = c(3,2),
align.labels = list(
c("center","center"),
c("center", "top")
)
)
```
```{r}
hctreemap(tree_sectores, allowDrillToNode = TRUE) %>%
hc_title(text = "GVA, economic sector and region, 2016") %>%
hc_tooltip(pointFormat = "{point.name}:
GVA: {point.value:,.0f}") %>%
hc_exporting(enabled = TRUE)
```
### Regional Level
```{r include=FALSE}
tree_regions <- treemap(
Peru_sectores,
index=c("Regions", "sector"),
vSize="vab",
title = "GVA, region and economic sector, 2016 ",
vColor="vab",
type="value",
palette = "BuPu",
force.print.labels = F,
border.col = c("black", "white"),
border.lwds = c(3,2),
align.labels = list(
c("center","center"),
c("center", "top")
)
)
```
```{r}
hctreemap(tree_regions, allowDrillToNode = TRUE) %>%
hc_title(text = "GVA, region and economic sector, 2016") %>%
hc_tooltip(pointFormat = "{point.name}:
GVA: {point.value:,.0f}") %>%
hc_exporting(enabled = TRUE)
```
Agro and VABpc
=============================================================================
Row {.tabset .tabset-fade}
-------------------------------------------------------------
### %PEao in Agro vs. GVA per cápita
```{r}
options(scipen=10000)
peru_df <- read_excel("C:/Users/Usuario/Desktop/r_que_r/r_que_r/content/datasets/peru_tabla.xlsx")
peru_df <- peru_df %>%
filter(Year %in% c(2001 : 2016)) %>%
filter(id != "PE") %>%
mutate(Geo = case_when(
Geo == "Costa" ~ "Coast",
Geo == "Sierra" ~ "Highlands",
Geo == "Selva" ~ "Forest"
))
peru_df_A <- peru_df %>%
arrange(desc(Year)) %>%
distinct(Name, .keep_all = TRUE)
peru_df_B<- peru_df %>%
nest(-Name) %>%
mutate(data = map(data, mutate_mapping, hcaes(x= Year, y = PEAO_AGR_PER), drop = TRUE),
data = map(data, list_parse)) %>%
rename(ttdata = data)
peru_df_plot<-left_join(peru_df_A, peru_df_B)
pfmc_P <- tooltip_chart(
accesor = "ttdata",
hc_opts = list(
xAxis = list(type = "category")
)
)
vars_B <- c("Region", "Population", "PEAO")
tt_P <- tooltip_table(x = vars_B, y = sprintf("{point.%s}", vars_B))
ttt_P <- tt_P %>%
str_remove_all("point\\.") %>%
str_remove_all("\\s+")
peru_df_plot_b <- peru_df_plot %>%
mutate( "Population" = Poblacion,
"GVA pc" = VABpc_07,
"% AGR" = PEAO_AGR_PER)
peru_df_plot_b$Population <- format(peru_df_plot_b$Population, big.mark = ",", digits = 0)
peru_df_plot_b$PEAO <- format(peru_df_plot_b$PEAO, big.mark = ",", digits = 0)
peru_df_plot_b <- peru_df_plot_b %>%
mutate(
tttext_P = str_glue_data(peru_df_plot_b, ttt_P)
)
pfmc_P <- tooltip_chart(
width = 400,
height = 400,
accesor = "ttdata",
hc_opts = list(
title = list(text = "point.tttext_P", useHTML = TRUE),
xAxis = list(type = "category")
)
)
hchart( peru_df_plot_b, "scatter", hcaes(VABpc_07, PEAO_AGR_PER, name = Region, size = Poblacion, group = Geo)) %>%
hc_xAxis(type = "logarithmic", title = list(text = "GVA per capita (log scale)")) %>%
hc_yAxis(title = list(text = "% PEAO in agriculture")) %>%
hc_colors(c("#2980b9", "#2ecc71", "#d35400" )) %>%
hc_tooltip(useHTML = TRUE, pointFormatter = pfmc_P) %>%
hc_title (text = "GVA per capita VS. % PEAO in Agriculture, 2016") %>%
hc_subtitle(text = "PEAO: Actively occupied population. GVA per capita in constant 2007 PEN") %>%
hc_credits(enabled = TRUE, text = "Source: INEI") %>%
hc_add_theme(hc_theme_darkunica())
```