---
title: "Exportaciones de acero"
output:
flexdashboard::flex_dashboard:
theme: journal
social: menu
source_code: embed
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
library(rio)
library(ggplot2)
library(stringr)
library(dplyr)
library(tidyverse)
library(modelsummary)
library(kableExtra)
library(cluster)
library(sf)
```
```{r stup, include=FALSE}
library(rio)
partida_peru_eeuu = import("export_acero_x_partida.xlsx")
library(dplyr)
library(tidyr)
library(stringr)
partida_peru_eeuu <- partida_peru_eeuu %>%
mutate(`Descripción Arancelaria` = str_replace(`Descripción Arancelaria`, ".*?\\bDEMAS\\b\\s*", ""))
partida_peru_eeuu <- partida_peru_eeuu %>%
arrange(Monto)
```
1. Exportación de acero de Perú {data-icon="fa-signal"}
=====================================
Column {data-width=300}
-------------------------------------------------------------------------------------------------------
### Principales partidas de acero hacia EE.UU.
```{r}
library(ggplot2)
library(dplyr)
library(stringr)
library(scales)
library(plotly)
# Ajustar los nombres en dos líneas para que se vean mejor en el tooltip
partida_peru_eeuu <- partida_peru_eeuu %>%
mutate(`Descripción Arancelaria` = str_wrap(`Descripción Arancelaria`, width = 25))
# Crear el gráfico base
grafico <- ggplot(partida_peru_eeuu, aes(x = reorder(`Descripción Arancelaria`, Monto), y = Monto, text = `Descripción Arancelaria`)) +
geom_bar(stat = "identity", fill = "#1F497D", width = 0.7) +
geom_text(aes(label = comma(Monto)), hjust = -9, nudge_y = max(partida_peru_eeuu$Monto) * 0.08,
size = 3.5, color = "black", fontface = "bold") +
coord_flip() +
theme_minimal(base_size = 14) +
labs(x = "", y = "Valor FOB (MILES US$)", title = "Descripción Arancelaria de las partidas de acero") +
theme(
axis.text.y = element_blank(), # Ocultar nombres en el eje Y
axis.ticks.y = element_blank(),
axis.text.x = element_text(size = 6, color = "black"),
plot.title = element_text(hjust = 0.5, face = "bold", size = 16),
panel.grid.major.y = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_rect(fill = "white", color = NA),
plot.margin = margin(10, 10, 10, 10), # Aumentar margen derecho
clip = "off"
) +
scale_y_continuous(expand = expansion(mult = c(0, 0.2))) # Más espacio a la derecha
# Convertir a gráfico interactivo con tooltips
grafico_interactivo <- ggplotly(grafico, tooltip = "text")
# Mostrar el gráfico
grafico_interactivo
```
Column {data-width=300}
-----------------------------------------------------------------------
### Comparación entre la exportación de acero hacia Estados Unidos y el resto del mundo
```{r}
peru_vs_mundo <- data.frame(
País = c("Estados Unidos", "Mundo"),
Monto = c(5904, 305819)
)
# Crear el gráfico
comparacion = ggplot(peru_vs_mundo, aes(x = País, y = Monto, fill = País)) +
geom_bar(stat = "identity", width = 0.5) +
geom_text(aes(label = scales::comma(Monto)), vjust = -0.5, fontface = "bold") +
scale_y_continuous(labels = scales::comma) +
scale_fill_manual(values = c("Perú" = "steelblue", "Mundo" = "firebrick")) +
labs(
title = "Exportaciones de acero de Perú",
subtitle = "Comparación entre la exportación hacia Estados Unidos y el mundo",
y = "Valor FOB (MILES US$)",
x = NULL
) +
theme_minimal() +
theme(legend.position = "none",
plot.title = element_text(face = "bold", hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5))
comparacion
```