Se cargan las librerías necesarias y el dataset Global Oil and Gas Extraction Tracker (GOGET), que contiene registros de unidades de extracción de petróleo y gas a nivel mundial.
library(readxl)
library(dplyr)
library(gt)
library(ggplot2)
library(scales)
library(forcats)
library(stringr)
datos <- readRDS("C:/Users/HP/Documents/petro.rds") %>%
mutate(Country = trimws(Country)) %>%
# Ajustar si el nombre de columna difiere
filter(!is.na(Country), Country != "NA", Country != "",
!is.na(`Unit type`), `Unit type` != "NA")
cat("Registros válidos:", nrow(datos), "\n")
## Registros válidos: 8334
cat("Variables:", ncol(datos), "\n")
## Variables: 32
Se extrae la variable País (Country). Es una variable de escala nominal: sus categorías no tienen orden jerárquico intrínseco. Para el análisis regional, cada país se clasifica en su continente correspondiente mediante una función de asignación geográfica estándar.
asignar_continente <- function(pais) {
case_when(
# América del Norte
pais %in% c("United States", "Canada", "Mexico", "Greenland") ~
"América del Norte",
# América del Sur y Caribe
pais %in% c("Venezuela", "Brazil", "Colombia", "Argentina", "Ecuador",
"Peru", "Bolivia", "Trinidad and Tobago", "Guyana", "Suriname",
"Chile", "Cuba", "Paraguay", "Uruguay", "Panama", "Costa Rica",
"Honduras", "Guatemala", "Nicaragua", "El Salvador",
"Barbados", "Haiti", "Dominican Republic", "Jamaica",
"Belize", "Bahamas") ~
"América del Sur y Caribe",
# Europa y Rusia
pais %in% c("Norway", "United Kingdom", "Denmark", "Netherlands", "Germany",
"Poland", "Romania", "Albania", "Serbia", "Croatia", "Hungary",
"Czech Republic", "Austria", "Italy", "France", "Spain", "Greece",
"Bulgaria", "Slovakia", "Ukraine", "Belarus", "Moldova",
"Latvia", "Lithuania", "Estonia", "Finland", "Sweden",
"Switzerland", "Belgium", "Portugal", "Ireland",
"Bosnia and Herzegovina", "North Macedonia", "Montenegro",
"Slovenia", "Kosovo", "Cyprus", "Russia") ~
"Europa y Rusia",
# Asia Central y Cáucaso
pais %in% c("Kazakhstan", "Azerbaijan", "Turkmenistan", "Uzbekistan",
"Kyrgyzstan", "Tajikistan", "Georgia", "Armenia") ~
"Asia Central y Cáucaso",
# Oriente Medio
pais %in% c("Saudi Arabia", "Iraq", "Iran", "Kuwait",
"United Arab Emirates", "Qatar", "Bahrain", "Oman",
"Yemen", "Syria", "Jordan", "Israel", "Lebanon", "Turkey") ~
"Oriente Medio",
# África
pais %in% c("Nigeria", "Angola", "Libya", "Algeria", "Egypt", "Tunisia",
"Gabon", "Republic of the Congo",
"Democratic Republic of the Congo", "Congo", "Cameroon",
"Sudan", "South Sudan", "Chad", "Equatorial Guinea",
"Mozambique", "Tanzania", "Cote d'Ivoire", "Ivory Coast",
"Ghana", "Niger", "Somalia", "Morocco", "Namibia",
"Madagascar", "Senegal", "Mauritania", "Uganda", "Kenya",
"Ethiopia", "South Africa", "Zambia", "Zimbabwe") ~
"África",
# Asia Pacífico y Oceanía
pais %in% c("China", "India", "Indonesia", "Malaysia", "Vietnam",
"Thailand", "Myanmar", "Bangladesh", "Pakistan", "Brunei",
"Philippines", "Japan", "South Korea", "North Korea",
"Taiwan", "Mongolia", "Papua New Guinea", "Timor-Leste",
"East Timor", "Cambodia", "Laos", "Sri Lanka",
"Afghanistan", "Nepal", "Australia", "New Zealand") ~
"Asia Pacífico y Oceanía",
TRUE ~ "Otro/No especificado"
)
}
datos <- datos %>%
mutate(Continente = asignar_continente(Country))
n <- nrow(datos)
cat("Variable analizada: País (Country)\n")
## Variable analizada: País (Country)
cat("Total de observaciones (n):", n, "\n")
## Total de observaciones (n): 8334
cat("Número de países únicos:", n_distinct(datos$Country), "\n")
## Número de países únicos: 104
cat("Continentes identificados:",
paste(sort(unique(datos$Continente)), collapse = ", "), "\n")
## Continentes identificados: África, América del Norte, América del Sur y Caribe, Asia Central y Cáucaso, Asia Pacífico y Oceanía, Europa y Rusia, Oriente Medio, Otro/No especificado
Se calculan la frecuencia absoluta (nᵢ), la frecuencia relativa en proporción (hᵢ) y en porcentaje (hᵢ %) para cada país y, de forma agregada, para cada continente, ordenadas de mayor a menor.
## ── Tabla por País ────────────────────────────────────────────────────────────
tabla_freq_pais <- datos %>%
count(Country, name = "ni") %>%
arrange(desc(ni)) %>%
rename(Pais = Country) %>%
mutate(
hi_prop = ni / n,
hi_pct = hi_prop * 100,
i = row_number()
) %>%
select(i, Pais, ni, hi_pct, hi_prop)
k_pais <- nrow(tabla_freq_pais)
cat("── Análisis por País ──\n")
## ── Análisis por País ──
cat("Número de países (k) :", k_pais, "\n")
## Número de países (k) : 104
cat("País más frecuente :", tabla_freq_pais$Pais[1],
"—", tabla_freq_pais$ni[1], "registros\n")
## País más frecuente : United States — 3093 registros
cat("País menos frecuente :", tabla_freq_pais$Pais[k_pais],
"—", tabla_freq_pais$ni[k_pais], "registro(s)\n")
## País menos frecuente : Zimbabwe — 1 registro(s)
cat("Verificación — Σnᵢ :", sum(tabla_freq_pais$ni),
"(debe ser", n, ")\n")
## Verificación — Σnᵢ : 8334 (debe ser 8334 )
cat("Verificación — Σhᵢ% :", round(sum(tabla_freq_pais$hi_pct), 2),
"(debe ser 100)\n")
## Verificación — Σhᵢ% : 100 (debe ser 100)
## ── Tabla por Continente ──────────────────────────────────────────────────────
tabla_freq_cont <- datos %>%
count(Continente, name = "ni") %>%
arrange(desc(ni)) %>%
mutate(
hi_prop = ni / n,
hi_pct = hi_prop * 100,
i = row_number()
) %>%
select(i, Continente, ni, hi_pct, hi_prop)
k_cont <- nrow(tabla_freq_cont)
cat("── Análisis por Continente ──\n")
## ── Análisis por Continente ──
cat("Número de continentes (k) :", k_cont, "\n")
## Número de continentes (k) : 8
cat("Continente más frecuente :", tabla_freq_cont$Continente[1],
"—", tabla_freq_cont$ni[1], "registros\n")
## Continente más frecuente : América del Norte — 4468 registros
cat("Continente menos frecuente :", tabla_freq_cont$Continente[k_cont],
"—", tabla_freq_cont$ni[k_cont], "registro(s)\n")
## Continente menos frecuente : Otro/No especificado — 35 registro(s)
cat("Verificación — Σnᵢ :", sum(tabla_freq_cont$ni),
"(debe ser", n, ")\n")
## Verificación — Σnᵢ : 8334 (debe ser 8334 )
cat("Verificación — Σhᵢ% :", round(sum(tabla_freq_cont$hi_pct), 2),
"(debe ser 100)\n")
## Verificación — Σhᵢ% : 100 (debe ser 100)
tabla_freq_pais %>%
gt() %>%
tab_header(
title = md("**Tabla N. 1**"),
subtitle = md("Distribución de frecuencias por país — yacimientos de petróleo y gas")
) %>%
cols_label(
i = md("**N°**"),
Pais = md("**País**"),
ni = md("**nᵢ**"),
hi_pct = md("**(%)** "),
hi_prop = md("**(proporción)**")
) %>%
tab_spanner(label = md("**hᵢ**"), columns = c(hi_pct, hi_prop)) %>%
fmt_number(columns = ni, decimals = 0, use_seps = TRUE) %>%
fmt_number(columns = hi_pct, decimals = 2) %>%
fmt_number(columns = hi_prop, decimals = 4) %>%
grand_summary_rows(
columns = c(ni, hi_pct, hi_prop),
fns = list(label = "Total", fn = "sum"),
fmt = list(
~ fmt_number(., columns = ni, decimals = 0, use_seps = TRUE),
~ fmt_number(., columns = hi_pct, decimals = 2),
~ fmt_number(., columns = hi_prop, decimals = 4)
)
) %>%
tab_source_note("Autor: Grupo 5") %>%
tab_options(
table.width = pct(75),
table.font.size = px(13),
table.font.names = "Arial",
heading.title.font.size = px(15),
heading.subtitle.font.size = px(12),
heading.align = "center",
heading.background.color = "#AAAAAA",
column_labels.font.weight = "bold",
column_labels.background.color = "#FFFFFF",
column_labels.border.top.color = "#AAAAAA",
column_labels.border.bottom.color = "#AAAAAA",
table.border.top.color = "#AAAAAA",
table.border.bottom.color = "#AAAAAA"
) %>%
tab_style(
style = cell_text(color = "white", weight = "bold"),
locations = cells_title(groups = c("title", "subtitle"))
) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = list(cells_column_labels(), cells_column_spanners(),
cells_grand_summary())
)
| Tabla N. 1 | |||||
| Distribución de frecuencias por país — yacimientos de petróleo y gas | |||||
| N° | País | nᵢ |
hᵢ
|
||
|---|---|---|---|---|---|
| (%) | (proporción) | ||||
| 1 | United States | 3,093 | 37.11 | 0.3711 | |
| 2 | Canada | 1,178 | 14.13 | 0.1413 | |
| 3 | United Kingdom | 317 | 3.80 | 0.0380 | |
| 4 | Colombia | 288 | 3.46 | 0.0346 | |
| 5 | Russia | 277 | 3.32 | 0.0332 | |
| 6 | Nigeria | 246 | 2.95 | 0.0295 | |
| 7 | Argentina | 202 | 2.42 | 0.0242 | |
| 8 | Mexico | 197 | 2.36 | 0.0236 | |
| 9 | Australia | 179 | 2.15 | 0.0215 | |
| 10 | Netherlands | 164 | 1.97 | 0.0197 | |
| 11 | Venezuela | 128 | 1.54 | 0.0154 | |
| 12 | Norway | 113 | 1.36 | 0.0136 | |
| 13 | China | 111 | 1.33 | 0.0133 | |
| 14 | Poland | 111 | 1.33 | 0.0133 | |
| 15 | Iran | 100 | 1.20 | 0.0120 | |
| 16 | Brazil | 97 | 1.16 | 0.0116 | |
| 17 | Egypt | 96 | 1.15 | 0.0115 | |
| 18 | Ecuador | 93 | 1.12 | 0.0112 | |
| 19 | Angola | 77 | 0.92 | 0.0092 | |
| 20 | Indonesia | 76 | 0.91 | 0.0091 | |
| 21 | Malaysia | 73 | 0.88 | 0.0088 | |
| 22 | Romania | 67 | 0.80 | 0.0080 | |
| 23 | Algeria | 58 | 0.70 | 0.0070 | |
| 24 | Iraq | 57 | 0.68 | 0.0068 | |
| 25 | India | 56 | 0.67 | 0.0067 | |
| 26 | Germany | 52 | 0.62 | 0.0062 | |
| 27 | Kazakhstan | 47 | 0.56 | 0.0056 | |
| 28 | Thailand | 42 | 0.50 | 0.0050 | |
| 29 | United Arab Emirates | 42 | 0.50 | 0.0050 | |
| 30 | Libya | 41 | 0.49 | 0.0049 | |
| 31 | Oman | 41 | 0.49 | 0.0049 | |
| 32 | Italy | 38 | 0.46 | 0.0046 | |
| 33 | Pakistan | 38 | 0.46 | 0.0046 | |
| 34 | Trinidad and Tobago | 35 | 0.42 | 0.0042 | |
| 35 | Saudi Arabia | 28 | 0.34 | 0.0034 | |
| 36 | Peru | 26 | 0.31 | 0.0031 | |
| 37 | Vietnam | 26 | 0.31 | 0.0031 | |
| 38 | Qatar | 25 | 0.30 | 0.0030 | |
| 39 | Denmark | 23 | 0.28 | 0.0028 | |
| 40 | Turkmenistan | 23 | 0.28 | 0.0028 | |
| 41 | Azerbaijan | 22 | 0.26 | 0.0026 | |
| 42 | Tanzania | 22 | 0.26 | 0.0026 | |
| 43 | Guyana | 19 | 0.23 | 0.0023 | |
| 44 | Mozambique | 17 | 0.20 | 0.0020 | |
| 45 | Ukraine | 16 | 0.19 | 0.0019 | |
| 46 | Ireland | 15 | 0.18 | 0.0018 | |
| 47 | Brunei | 14 | 0.17 | 0.0017 | |
| 48 | Israel | 14 | 0.17 | 0.0017 | |
| 49 | Kuwait | 14 | 0.17 | 0.0017 | |
| 50 | Republic of the Congo | 14 | 0.17 | 0.0017 | |
| 51 | Bolivia | 11 | 0.13 | 0.0013 | |
| 52 | Chad | 10 | 0.12 | 0.0012 | |
| 53 | Cuba | 10 | 0.12 | 0.0012 | |
| 54 | Syria | 8 | 0.10 | 0.0010 | |
| 55 | Bangladesh | 7 | 0.08 | 0.0008 | |
| 56 | New Zealand | 7 | 0.08 | 0.0008 | |
| 57 | Barbados | 6 | 0.07 | 0.0007 | |
| 58 | Kuwait-Saudi Arabia | 6 | 0.07 | 0.0007 | |
| 59 | Myanmar | 6 | 0.07 | 0.0007 | |
| 60 | Türkiye | 6 | 0.07 | 0.0007 | |
| 61 | Cyprus | 5 | 0.06 | 0.0006 | |
| 62 | Côte d'Ivoire | 5 | 0.06 | 0.0006 | |
| 63 | Ethiopia | 5 | 0.06 | 0.0006 | |
| 64 | Namibia | 5 | 0.06 | 0.0006 | |
| 65 | Papua New Guinea | 5 | 0.06 | 0.0006 | |
| 66 | South Sudan | 5 | 0.06 | 0.0006 | |
| 67 | Suriname | 5 | 0.06 | 0.0006 | |
| 68 | Tunisia | 5 | 0.06 | 0.0006 | |
| 69 | Cameroon | 4 | 0.05 | 0.0005 | |
| 70 | Ghana | 4 | 0.05 | 0.0005 | |
| 71 | Guatemala | 4 | 0.05 | 0.0005 | |
| 72 | Mauritania | 4 | 0.05 | 0.0005 | |
| 73 | South Africa | 4 | 0.05 | 0.0005 | |
| 74 | Austria | 3 | 0.04 | 0.0004 | |
| 75 | Iran-Iraq | 3 | 0.04 | 0.0004 | |
| 76 | Senegal | 3 | 0.04 | 0.0004 | |
| 77 | Uganda | 3 | 0.04 | 0.0004 | |
| 78 | Bahrain | 2 | 0.02 | 0.0002 | |
| 79 | France | 2 | 0.02 | 0.0002 | |
| 80 | Gabon | 2 | 0.02 | 0.0002 | |
| 81 | Hungary | 2 | 0.02 | 0.0002 | |
| 82 | Kenya | 2 | 0.02 | 0.0002 | |
| 83 | Kuwait-Saudi Arabia-Iran | 2 | 0.02 | 0.0002 | |
| 84 | Philippines | 2 | 0.02 | 0.0002 | |
| 85 | Russia-Kazakhstan | 2 | 0.02 | 0.0002 | |
| 86 | Thailand-Malaysia | 2 | 0.02 | 0.0002 | |
| 87 | Timor-Leste | 2 | 0.02 | 0.0002 | |
| 88 | Albania | 1 | 0.01 | 0.0001 | |
| 89 | Chile | 1 | 0.01 | 0.0001 | |
| 90 | China-Japan | 1 | 0.01 | 0.0001 | |
| 91 | Grenada | 1 | 0.01 | 0.0001 | |
| 92 | Jamaica | 1 | 0.01 | 0.0001 | |
| 93 | Japan | 1 | 0.01 | 0.0001 | |
| 94 | Madagascar | 1 | 0.01 | 0.0001 | |
| 95 | Morocco | 1 | 0.01 | 0.0001 | |
| 96 | Palestine | 1 | 0.01 | 0.0001 | |
| 97 | Saudi Arabia-Bahrain | 1 | 0.01 | 0.0001 | |
| 98 | Saudi Arabia-Iran | 1 | 0.01 | 0.0001 | |
| 99 | Senegal-Mauritania | 1 | 0.01 | 0.0001 | |
| 100 | Spain | 1 | 0.01 | 0.0001 | |
| 101 | Timor Gap | 1 | 0.01 | 0.0001 | |
| 102 | United Arab Emirates-Iran | 1 | 0.01 | 0.0001 | |
| 103 | Vietnam-Malaysia | 1 | 0.01 | 0.0001 | |
| 104 | Zimbabwe | 1 | 0.01 | 0.0001 | |
| Total | — | — | 8,334 | 100.00 | 1.0000 |
| Autor: Grupo 5 | |||||
tabla_freq_cont %>%
gt() %>%
tab_header(
title = md("**Tabla N. 2**"),
subtitle = md("Distribución de frecuencias por continente — yacimientos de petróleo y gas")
) %>%
cols_label(
i = md("**N°**"),
Continente = md("**Continente**"),
ni = md("**nᵢ**"),
hi_pct = md("**(%)** "),
hi_prop = md("**(proporción)**")
) %>%
tab_spanner(label = md("**hᵢ**"), columns = c(hi_pct, hi_prop)) %>%
fmt_number(columns = ni, decimals = 0, use_seps = TRUE) %>%
fmt_number(columns = hi_pct, decimals = 2) %>%
fmt_number(columns = hi_prop, decimals = 4) %>%
grand_summary_rows(
columns = c(ni, hi_pct, hi_prop),
fns = list(label = "Total", fn = "sum"),
fmt = list(
~ fmt_number(., columns = ni, decimals = 0, use_seps = TRUE),
~ fmt_number(., columns = hi_pct, decimals = 2),
~ fmt_number(., columns = hi_prop, decimals = 4)
)
) %>%
tab_source_note("Autor: Grupo 5") %>%
tab_options(
table.width = pct(75),
table.font.size = px(13),
table.font.names = "Arial",
heading.title.font.size = px(15),
heading.subtitle.font.size = px(12),
heading.align = "center",
heading.background.color = "#AAAAAA",
column_labels.font.weight = "bold",
column_labels.background.color = "#FFFFFF",
column_labels.border.top.color = "#AAAAAA",
column_labels.border.bottom.color = "#AAAAAA",
table.border.top.color = "#AAAAAA",
table.border.bottom.color = "#AAAAAA"
) %>%
tab_style(
style = cell_text(color = "white", weight = "bold"),
locations = cells_title(groups = c("title", "subtitle"))
) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = list(cells_column_labels(), cells_column_spanners(),
cells_grand_summary())
)
| Tabla N. 2 | |||||
| Distribución de frecuencias por continente — yacimientos de petróleo y gas | |||||
| N° | Continente | nᵢ |
hᵢ
|
||
|---|---|---|---|---|---|
| (%) | (proporción) | ||||
| 1 | América del Norte | 4,468 | 53.61 | 0.5361 | |
| 2 | Europa y Rusia | 1,207 | 14.48 | 0.1448 | |
| 3 | América del Sur y Caribe | 926 | 11.11 | 0.1111 | |
| 4 | Asia Pacífico y Oceanía | 645 | 7.74 | 0.0774 | |
| 5 | África | 630 | 7.56 | 0.0756 | |
| 6 | Oriente Medio | 331 | 3.97 | 0.0397 | |
| 7 | Asia Central y Cáucaso | 92 | 1.10 | 0.0110 | |
| 8 | Otro/No especificado | 35 | 0.42 | 0.0042 | |
| Total | — | — | 8,334 | 100.00 | 1.0000 |
| Autor: Grupo 5 | |||||
## ── Datos para graficar ───────────────────────────────────────────────────────
cont_graf <- tabla_freq_cont %>%
mutate(Continente = fct_reorder(Continente, ni))
# Frecuencias acumuladas (globales): se calculan en orden de mayor a menor
# frecuencia, ya que la variable es nominal y no tiene un orden natural.
cont_acum <- tabla_freq_cont %>%
arrange(desc(ni)) %>%
mutate(
Ni_ac = cumsum(ni),
hi_ac_pct = cumsum(hi_pct),
Continente = factor(Continente, levels = Continente)
)
## ── Paletas de colores ────────────────────────────────────────────────────────
# Continentes: color distinto por región
colores_cont <- c(
"América del Norte" = "#1A5276",
"América del Sur y Caribe" = "#1E8449",
"Europa y Rusia" = "#C0392B",
"Asia Central y Cáucaso" = "#7D3C98",
"Oriente Medio" = "#D68910",
"África" = "#D4AC0D",
"Asia Pacífico y Oceanía" = "#148F77",
"Otro/No especificado" = "#AAB7B8"
)
## ── Etiqueta de fuente ────────────────────────────────────────────────────────
pie_label <- paste0("n = ", format(n, big.mark = ","),
" | Fuente: Global Energy Monitor — GOGET 2023")
## ── Tema para barras verticales (continentes) ─────────────────────────────────
tema_base <- theme_minimal(base_size = 12) +
theme(
legend.position = "none",
plot.title = element_text(face = "bold", size = 13),
plot.caption = element_text(color = "#888888", size = 9, hjust = 0),
axis.title = element_text(face = "bold", size = 11),
axis.text.x = element_text(face = "bold", angle = 20, hjust = 1),
panel.grid.major.x = element_blank(),
panel.grid.major.y = element_line(color = "#EEEEEE"),
panel.grid.minor = element_blank(),
plot.background = element_rect(fill = "white", color = NA)
)
ggplot(cont_graf, aes(x = Continente, y = ni, fill = Continente)) +
geom_col(width = 0.55, color = "white") +
geom_text(aes(label = format(ni, big.mark = ",")),
vjust = -0.4, size = 3.5, fontface = "bold") +
scale_fill_manual(values = colores_cont) +
scale_x_discrete(labels = function(x) str_wrap(x, width = 12)) +
scale_y_continuous(labels = label_comma(),
expand = expansion(mult = c(0, 0.12))) +
labs(title = "Gráfica N. 4: Distribución de yacimientos por continente",
x = "Continente", y = "Frecuencia Absoluta (nᵢ)",
caption = pie_label) +
tema_base
Al ser una variable cualitativa nominal, los continentes no tienen un orden natural. Por ello, la frecuencia acumulada se calcula siguiendo el orden de mayor a menor frecuencia (criterio tipo Pareto), y no un orden propio de la variable.
ggplot(cont_acum, aes(x = Continente, y = Ni_ac, fill = Continente)) +
geom_col(width = 0.55, color = "white") +
geom_text(aes(label = format(Ni_ac, big.mark = ",")),
vjust = -0.4, size = 3.5, fontface = "bold") +
scale_fill_manual(values = colores_cont) +
scale_x_discrete(labels = function(x) str_wrap(x, width = 12)) +
scale_y_continuous(labels = label_comma(),
expand = expansion(mult = c(0, 0.12))) +
labs(title = "Gráfica N. 5: Distribución acumulada de yacimientos por continente",
x = "Continente", y = "Frecuencia Absoluta Acumulada (Nᵢ)",
caption = pie_label) +
tema_base
ggplot(cont_graf, aes(x = Continente, y = hi_pct, fill = Continente)) +
geom_col(width = 0.55, color = "white") +
geom_text(aes(label = paste0(round(hi_pct, 2), "%")),
vjust = -0.4, size = 3.5, fontface = "bold") +
scale_fill_manual(values = colores_cont) +
scale_x_discrete(labels = function(x) str_wrap(x, width = 12)) +
scale_y_continuous(labels = function(x) paste0(x, "%"),
expand = expansion(mult = c(0, 0.12))) +
labs(title = "Gráfica N. 6: Distribución porcentual por continente",
x = "Continente", y = "Frecuencia Relativa (%)",
caption = pie_label) +
tema_base
ggplot(cont_acum, aes(x = Continente, y = hi_ac_pct, fill = Continente)) +
geom_col(width = 0.55, color = "white") +
geom_text(aes(label = paste0(round(hi_ac_pct, 2), "%")),
vjust = -0.4, size = 3.5, fontface = "bold") +
scale_fill_manual(values = colores_cont) +
scale_x_discrete(labels = function(x) str_wrap(x, width = 12)) +
scale_y_continuous(labels = function(x) paste0(x, "%"),
expand = expansion(mult = c(0, 0.12))) +
labs(title = "Gráfica N. 7: Distribución porcentual acumulada por continente",
x = "Continente", y = "Frecuencia Relativa Acumulada (%)",
caption = pie_label) +
tema_base
tabla_freq_cont %>%
mutate(Continente = fct_reorder(Continente, hi_pct),
etiqueta = paste0(round(hi_pct, 1), "%")) %>%
ggplot(aes(x = "", y = hi_pct, fill = Continente)) +
geom_col(width = 1, color = "white") +
geom_text(aes(label = etiqueta),
position = position_stack(vjust = 0.5),
size = 4, fontface = "bold") +
coord_polar(theta = "y") +
scale_fill_manual(values = colores_cont) +
labs(title = "Gráfica N. 8: Distribución porcentual por continente",
fill = "Continente",
caption = pie_label) +
theme_void(base_size = 12) +
theme(
plot.title = element_text(face = "bold", size = 13, hjust = 0.5),
plot.caption = element_text(color = "#888888", size = 9, hjust = 0.5),
legend.position = "right",
legend.title = element_text(face = "bold", size = 10),
plot.background = element_rect(fill = "white", color = NA)
)
La variable País es cualitativa nominal. Para este tipo de variable, el único indicador de tendencia central aplicable es la moda, evaluada tanto a nivel de país individual como a nivel de continente. El resto de indicadores (dispersión y forma) no aplican por tratarse de una variable no numérica.
moda_pais <- tabla_freq_pais$Pais[1]
moda_pais_n <- tabla_freq_pais$ni[1]
moda_pais_pct <- round(tabla_freq_pais$hi_pct[1], 2)
moda_cont <- tabla_freq_cont$Continente[1]
moda_cont_n <- tabla_freq_cont$ni[1]
moda_cont_pct <- round(tabla_freq_cont$hi_pct[1], 2)
tabla_indicadores <- data.frame(
Variable = c("País", "Continente"),
Rango = c(paste0("D = {", k_pais, " países únicos}"),
paste0("D = {", k_cont, " continentes}")),
X = c("-", "-"),
Me = c("-", "-"),
Mo = c(paste0(moda_pais, " (", moda_pais_pct, "%)"),
paste0(moda_cont, " (", moda_cont_pct, "%)")),
Sd = c("-", "-"),
CV = c("-", "-"),
As = c("-", "-"),
K = c("-", "-"),
Outliers = c("-", "-"),
check.names = FALSE
)
tabla_indicadores %>%
gt() %>%
tab_header(
title = md("**INDICADORES ESTADÍSTICOS**")
) %>%
cols_label(
Variable = md("**Variable**"),
Rango = md("**Rango**"),
X = md("**X**"),
Me = md("**Me**"),
Mo = md("**Mo**"),
Sd = md("**Sd**"),
CV = md("**CV(%)**"),
As = md("**As**"),
K = md("**K**"),
Outliers = md("**Outliers**")
) %>%
tab_spanner(label = md("**Tendencia Central**"), columns = c(X, Me, Mo)) %>%
tab_spanner(label = md("**Dispersión**"), columns = c(Sd, CV)) %>%
tab_spanner(label = md("**Forma**"), columns = c(As, K)) %>%
tab_source_note("Autor: Grupo 5") %>%
tab_options(
table.width = pct(100),
table.font.size = px(12),
table.font.names = "Arial",
heading.align = "center",
heading.title.font.size = px(14),
heading.background.color = "#AAAAAA",
heading.border.bottom.color = "#AAAAAA",
column_labels.font.weight = "bold",
column_labels.background.color = "#FFFFFF",
column_labels.border.top.color = "#CCCCCC",
column_labels.border.top.width = px(1),
column_labels.border.bottom.color = "#CCCCCC",
column_labels.border.bottom.width = px(1),
table_body.border.bottom.color = "#CCCCCC",
table_body.border.bottom.width = px(1),
table.border.top.color = "#AAAAAA",
table.border.top.width = px(1),
table.border.bottom.color = "#AAAAAA",
table.border.bottom.width = px(1),
source_notes.font.size = px(11),
source_notes.border.lr.color = "transparent",
data_row.padding = px(5)
) %>%
tab_style(
style = cell_text(color = "white", weight = "bold"),
locations = cells_title(groups = "title")
) %>%
tab_style(
style = cell_text(color = "#333333", align = "center", weight = "bold"),
locations = list(cells_column_labels(), cells_column_spanners())
) %>%
tab_style(
style = cell_text(color = "#333333", align = "center"),
locations = cells_body(columns = c(X, Me, Mo, Sd, CV, As, K, Outliers))
) %>%
cols_align(align = "left", columns = c(Variable, Rango))
| INDICADORES ESTADÍSTICOS | |||||||||
| Variable | Rango |
Tendencia Central
|
Dispersión
|
Forma
|
Outliers | ||||
|---|---|---|---|---|---|---|---|---|---|
| X | Me | Mo | Sd | CV(%) | As | K | |||
| País | D = {104 países únicos} | - | - | United States (37.11%) | - | - | - | - | - |
| Continente | D = {8 continentes} | - | - | América del Norte (53.61%) | - | - | - | - | - |
| Autor: Grupo 5 | |||||||||
El valor más frecuente de “país” es “United States”. A nivel continental el valor más frecuente es América del Norte.