##
## ╔══════════════════════════════════════════════════════════╗
## ║ DASHBOARD INTERACTIVO — GAPMINDER ║
## ║ Exploración del Desarrollo Humano Mundial ║
## ╠══════════════════════════════════════════════════════════╣
## ║ Integrantes del equipo: ║
## ║ • Estudiante 1 ║
## ║ • Estudiante 2 ║
## ║ • Estudiante 3 ║
## ╠══════════════════════════════════════════════════════════╣
## ║ Repositorio GitHub: ║
## ║ https://github.com/usuario/gapminder-dashboard ║
## ║ ║
## ║ Dashboard en línea: ║
## ║ https://usuario.shinyapps.io/gap-dashboard ║
## ╚══════════════════════════════════════════════════════════╝
El objetivo de este proyecto es desarrollar una aplicación web interactiva en R Shiny que permita a los usuarios explorar de manera visual e intuitiva los indicadores de desarrollo humano del dataset Gapminder, integrando:
dplyrggplot2plotlyshiny| Recurso | Enlace |
|---|---|
| Repositorio GitHub | github.com/usuario/gapminder-dashboard |
| Dashboard Shiny | usuario.shinyapps.io/gap-dashboard |
| Este informe | rpubs.com/usuario/gapminder-pac |
## Rows: 1,704
## Columns: 6
## $ country <fct> "Afghanistan", "Afghanistan", "Afghanistan", "Afghanistan", …
## $ continent <fct> Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, …
## $ year <int> 1952, 1957, 1962, 1967, 1972, 1977, 1982, 1987, 1992, 1997, …
## $ lifeExp <dbl> 28.801, 30.332, 31.997, 34.020, 36.088, 38.438, 39.854, 40.8…
## $ pop <int> 8425333, 9240934, 10267083, 11537966, 13079460, 14880372, 12…
## $ gdpPercap <dbl> 779.4453, 820.8530, 853.1007, 836.1971, 739.9811, 786.1134, …
## country continent year lifeExp
## Afghanistan: 12 Africa :624 Min. :1952 Min. :23.60
## Albania : 12 Americas:300 1st Qu.:1966 1st Qu.:48.20
## Algeria : 12 Asia :396 Median :1980 Median :60.71
## Angola : 12 Europe :360 Mean :1980 Mean :59.47
## Argentina : 12 Oceania : 24 3rd Qu.:1993 3rd Qu.:70.85
## Australia : 12 Max. :2007 Max. :82.60
## (Other) :1632
## pop gdpPercap
## Min. :6.001e+04 Min. : 241.2
## 1st Qu.:2.794e+06 1st Qu.: 1202.1
## Median :7.024e+06 Median : 3531.8
## Mean :2.960e+07 Mean : 7215.3
## 3rd Qu.:1.959e+07 3rd Qu.: 9325.5
## Max. :1.319e+09 Max. :113523.1
##
El dataset Gapminder contiene:
info <- data.frame(
Atributo = c("Observaciones", "Variables", "Países", "Continentes",
"Período", "Intervalo"),
Valor = c(nrow(gapminder), ncol(gapminder),
n_distinct(gapminder$country),
n_distinct(gapminder$continent),
paste(min(gapminder$year), "–", max(gapminder$year)),
"Cada 5 años")
)
kable(info, caption = "Información general del dataset Gapminder")| Atributo | Valor |
|---|---|
| Observaciones | 1704 |
| Variables | 6 |
| Países | 142 |
| Continentes | 5 |
| Período | 1952 – 2007 |
| Intervalo | Cada 5 años |
variables <- data.frame(
Variable = c("country", "continent", "year", "lifeExp", "pop", "gdpPercap"),
Tipo = c("Factor", "Factor", "Entero", "Numérico", "Entero", "Numérico"),
Descripción = c(
"Nombre del país (142 niveles)",
"Continente (5 niveles: Africa, Americas, Asia, Europe, Oceania)",
"Año de la observación (1952, 1957, ..., 2007)",
"Esperanza de vida al nacer (años)",
"Población total del país",
"PIB per cápita en dólares ajustados por inflación (USD)"
)
)
kable(variables, caption = "Descripción de las variables del dataset")| Variable | Tipo | Descripción |
|---|---|---|
| country | Factor | Nombre del país (142 niveles) |
| continent | Factor | Continente (5 niveles: Africa, Americas, Asia, Europe, Oceania) |
| year | Entero | Año de la observación (1952, 1957, …, 2007) |
| lifeExp | Numérico | Esperanza de vida al nacer (años) |
| pop | Entero | Población total del país |
| gdpPercap | Numérico | PIB per cápita en dólares ajustados por inflación (USD) |
La aplicación Shiny se estructura en dos componentes principales:
ui <- fluidPage(
# Cabecera con título personalizado
titlePanel("Dashboard Gapminder"),
sidebarLayout(
sidebarPanel(
selectInput("continente", "Continente:", choices = continentes),
uiOutput("ui_pais"), # dinámico según continente
sliderInput("anio", "Año:",
min = 1952, max = 2007, value = c(1952, 2007), step = 5),
uiOutput("kpis") # KPIs reactivos
),
mainPanel(
tabsetPanel(
tabPanel("Tendencias", ...), # 3 gráficos de serie temporal
tabPanel("Continentes", ...), # boxplots + gráfico burbuja
tabPanel("Modelo", ...), # regresión lineal + residuos
tabPanel("Datos", ...) # tabla interactiva DT
)
)
)
)server <- function(input, output, session) {
# Datos filtrados reactivamente
datos_cont <- reactive({
gapminder %>%
filter(year >= input$anio[1], year <= input$anio[2]) %>%
{ if (input$continente != "Todos") filter(., continent == input$continente) else . }
})
# Modelo de regresión
modelo <- reactive({
lm(lifeExp ~ log(gdpPercap) + year + continent, data = datos_cont())
})
}pais_ejemplo <- gapminder %>% filter(country == "Peru")
p1 <- ggplot(pais_ejemplo, aes(x = year, y = lifeExp)) +
geom_line(color = "#1abc9c", size = 1.3) +
geom_point(color = "#16a085", size = 3.5) +
labs(title = "Esperanza de vida — Perú",
subtitle = "Evolución 1952–2007",
x = "Año", y = "Años de vida") +
theme_minimal(base_size = 13)
ggplotly(p1)p2 <- gapminder %>%
filter(year == 2007) %>%
ggplot(aes(x = reorder(continent, lifeExp, median),
y = lifeExp, fill = continent)) +
geom_boxplot(alpha = 0.75, show.legend = FALSE) +
geom_jitter(width = 0.2, alpha = 0.3, size = 1.2) +
labs(title = "Distribución de esperanza de vida por continente (2007)",
x = NULL, y = "Años de vida") +
theme_minimal(base_size = 13)
ggplotly(p2)p3 <- gapminder %>%
filter(year == 2007) %>%
ggplot(aes(x = gdpPercap, y = lifeExp,
size = pop / 1e6, color = continent,
text = paste0("<b>", country, "</b><br>",
"PIB: $", round(gdpPercap), "<br>",
"Vida: ", round(lifeExp, 1), " años"))) +
geom_point(alpha = 0.65) +
scale_x_log10(labels = scales::comma) +
scale_size(range = c(2, 18), name = "Población (M)") +
labs(title = "PIB per cápita vs Esperanza de vida — 2007",
subtitle = "Tamaño de burbuja proporcional a la población",
x = "PIB per cápita (USD, escala logarítmica)",
y = "Esperanza de vida (años)",
color = "Continente") +
theme_minimal(base_size = 13)
ggplotly(p3, tooltip = "text")gapminder_modelo <- gapminder %>%
mutate(log_gdp = log(gdpPercap))
modelo <- lm(lifeExp ~ log_gdp + year + continent,
data = gapminder_modelo)
summary(modelo)##
## Call:
## lm(formula = lifeExp ~ log_gdp + year + continent, data = gapminder_modelo)
##
## Residuals:
## Min 1Q Median 3Q Max
## -25.0433 -3.2175 0.3482 3.6657 15.1321
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -4.659e+02 1.667e+01 -27.94 <2e-16 ***
## log_gdp 5.024e+00 1.595e-01 31.50 <2e-16 ***
## year 2.416e-01 8.586e-03 28.14 <2e-16 ***
## continentAmericas 8.926e+00 4.630e-01 19.28 <2e-16 ***
## continentAsia 7.063e+00 3.959e-01 17.84 <2e-16 ***
## continentEurope 1.251e+01 5.097e-01 24.54 <2e-16 ***
## continentOceania 1.275e+01 1.275e+00 10.00 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.813 on 1697 degrees of freedom
## Multiple R-squared: 0.7982, Adjusted R-squared: 0.7975
## F-statistic: 1119 on 6 and 1697 DF, p-value: < 2.2e-16
p4 <- ggplot(gapminder_modelo, aes(x = log_gdp, y = lifeExp, color = continent)) +
geom_point(alpha = 0.3, size = 1.5) +
geom_smooth(method = "lm", se = TRUE, size = 1.1) +
labs(title = "Regresión: log(PIB per cápita) vs Esperanza de vida",
subtitle = paste0("R² = ", round(summary(modelo)$r.squared, 3)),
x = "log(PIB per cápita)",
y = "Esperanza de vida (años)",
color = "Continente") +
theme_minimal(base_size = 13)
ggplotly(p4)df_res <- data.frame(
ajustados = fitted(modelo),
residuos = residuals(modelo)
)
p5 <- ggplot(df_res, aes(x = ajustados, y = residuos)) +
geom_point(alpha = 0.35, color = "#8e44ad", size = 1.5) +
geom_hline(yintercept = 0, color = "#e74c3c", linetype = "dashed", size = 1) +
geom_smooth(se = FALSE, color = "#3498db", size = 1) +
labs(title = "Residuos vs Valores ajustados",
x = "Valores ajustados", y = "Residuos") +
theme_minimal(base_size = 13)
ggplotly(p5)Bryan, J. (2017). gapminder: Data from Gapminder. R package version 0.3.0. https://CRAN.R-project.org/package=gapminder
Chang, W., Cheng, J., Allaire, J., Xie, Y., & McPherson, J. (2021). shiny: Web Application Framework for R. https://CRAN.R-project.org/package=shiny
Heiss, F. (2020). Using R for Introductory Econometrics (2nd ed.). http://www.urfie.net/
Rosling, H., Rönnlund, A. R., & Rosling, O. (2018). Factfulness: Ten Reasons We’re Wrong About the World—and Why Things Are Better Than You Think. Flatiron Books.
Wickham, H. (2019). Advanced R (2nd ed.). Chapman & Hall/CRC. https://adv-r.hadley.nz/
Wickham, H. (2016). ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. https://ggplot2.tidyverse.org
Wickham, H., François, R., Henry, L., & Müller, K. (2021). dplyr: A Grammar of Data Manipulation. https://CRAN.R-project.org/package=dplyr
## R version 4.6.0 (2026-04-24 ucrt)
## Platform: x86_64-w64-mingw32/x64
## Running under: Windows 11 x64 (build 26200)
##
## Matrix products: default
## LAPACK version 3.12.1
##
## locale:
## [1] LC_COLLATE=Spanish_Peru.utf8 LC_CTYPE=Spanish_Peru.utf8
## [3] LC_MONETARY=Spanish_Peru.utf8 LC_NUMERIC=C
## [5] LC_TIME=Spanish_Peru.utf8
##
## time zone: America/Lima
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] knitr_1.51 plotly_4.12.0 ggplot2_4.0.3 dplyr_1.2.1
## [5] gapminder_1.0.1
##
## loaded via a namespace (and not attached):
## [1] Matrix_1.7-5 gtable_0.3.6 jsonlite_2.0.0 compiler_4.6.0
## [5] tidyselect_1.2.1 tidyr_1.3.2 jquerylib_0.1.4 splines_4.6.0
## [9] scales_1.4.0 yaml_2.3.12 fastmap_1.2.0 lattice_0.22-9
## [13] R6_2.6.1 labeling_0.4.3 generics_0.1.4 htmlwidgets_1.6.4
## [17] tibble_3.3.1 bslib_0.10.0 pillar_1.11.1 RColorBrewer_1.1-3
## [21] rlang_1.2.0 cachem_1.1.0 xfun_0.57 sass_0.4.10
## [25] S7_0.2.2 lazyeval_0.2.3 otel_0.2.0 viridisLite_0.4.3
## [29] cli_3.6.6 mgcv_1.9-4 withr_3.0.2 magrittr_2.0.5
## [33] crosstalk_1.2.2 digest_0.6.39 grid_4.6.0 rstudioapi_0.18.0
## [37] nlme_3.1-169 lifecycle_1.0.5 vctrs_0.7.3 evaluate_1.0.5
## [41] glue_1.8.1 data.table_1.18.4 farver_2.1.2 purrr_1.2.2
## [45] httr_1.4.8 rmarkdown_2.31 tools_4.6.0 pkgconfig_2.0.3
## [49] htmltools_0.5.9
Informe generado con R Markdown y publicado en RPubs.
Código fuente disponible en GitHub bajo licencia MIT.