1 Carga de Librerías

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)

#Leer datos

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

2 Selección de Variable

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

3 Conteo (Frecuencia)

Se calculan la frecuencia absoluta local (nᵢ) y global (Nᵢ, acumulada), y la frecuencia relativa local (hᵢ) y global (Hᵢ, acumulada), en proporción y en porcentaje, 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,
    Ni      = cumsum(ni),
    Hi_prop = cumsum(hi_prop),
    Hi_pct  = cumsum(hi_pct),
    i       = row_number()
  ) %>%
  select(i, Pais, ni, Ni, hi_pct, Hi_pct, hi_prop, 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,
    Ni      = cumsum(ni),
    Hi_prop = cumsum(hi_prop),
    Hi_pct  = cumsum(hi_pct),
    i       = row_number()
  ) %>%
  select(i, Continente, ni, Ni, hi_pct, Hi_pct, hi_prop, 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)

4 Tabla de Distribución de Frecuencias

4.1 Por País

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("**Local (nᵢ)**"),
    Ni      = md("**Global (Nᵢ)**"),
    hi_pct  = md("**Local (hᵢ %)**"),
    Hi_pct  = md("**Global (Hᵢ %)**"),
    hi_prop = md("**Local (hᵢ)**"),
    Hi_prop = md("**Global (Hᵢ)**")
  ) %>%
  tab_spanner(label = md("**Frecuencia absoluta**"),
              columns = c(ni, Ni)) %>%
  tab_spanner(label = md("**Frecuencia relativa (%)**"),
              columns = c(hi_pct, Hi_pct)) %>%
  tab_spanner(label = md("**Frecuencia relativa (proporción)**"),
              columns = c(hi_prop, Hi_prop)) %>%
  fmt_number(columns = c(ni, Ni),           decimals = 0, use_seps = TRUE) %>%
  fmt_number(columns = c(hi_pct, Hi_pct),   decimals = 2) %>%
  fmt_number(columns = c(hi_prop, 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(90),
    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
Frecuencia absoluta
Frecuencia relativa (%)
Frecuencia relativa (proporción)
Local (nᵢ) Global (Nᵢ) Local (hᵢ %) Global (Hᵢ %) Local (hᵢ) Global (Hᵢ)
1 United States 3,093 3,093 37.11 37.11 0.3711 0.3711
2 Canada 1,178 4,271 14.13 51.25 0.1413 0.5125
3 United Kingdom 317 4,588 3.80 55.05 0.0380 0.5505
4 Colombia 288 4,876 3.46 58.51 0.0346 0.5851
5 Russia 277 5,153 3.32 61.83 0.0332 0.6183
6 Nigeria 246 5,399 2.95 64.78 0.0295 0.6478
7 Argentina 202 5,601 2.42 67.21 0.0242 0.6721
8 Mexico 197 5,798 2.36 69.57 0.0236 0.6957
9 Australia 179 5,977 2.15 71.72 0.0215 0.7172
10 Netherlands 164 6,141 1.97 73.69 0.0197 0.7369
11 Venezuela 128 6,269 1.54 75.22 0.0154 0.7522
12 Norway 113 6,382 1.36 76.58 0.0136 0.7658
13 China 111 6,493 1.33 77.91 0.0133 0.7791
14 Poland 111 6,604 1.33 79.24 0.0133 0.7924
15 Iran 100 6,704 1.20 80.44 0.0120 0.8044
16 Brazil 97 6,801 1.16 81.61 0.0116 0.8161
17 Egypt 96 6,897 1.15 82.76 0.0115 0.8276
18 Ecuador 93 6,990 1.12 83.87 0.0112 0.8387
19 Angola 77 7,067 0.92 84.80 0.0092 0.8480
20 Indonesia 76 7,143 0.91 85.71 0.0091 0.8571
21 Malaysia 73 7,216 0.88 86.59 0.0088 0.8659
22 Romania 67 7,283 0.80 87.39 0.0080 0.8739
23 Algeria 58 7,341 0.70 88.08 0.0070 0.8808
24 Iraq 57 7,398 0.68 88.77 0.0068 0.8877
25 India 56 7,454 0.67 89.44 0.0067 0.8944
26 Germany 52 7,506 0.62 90.06 0.0062 0.9006
27 Kazakhstan 47 7,553 0.56 90.63 0.0056 0.9063
28 Thailand 42 7,595 0.50 91.13 0.0050 0.9113
29 United Arab Emirates 42 7,637 0.50 91.64 0.0050 0.9164
30 Libya 41 7,678 0.49 92.13 0.0049 0.9213
31 Oman 41 7,719 0.49 92.62 0.0049 0.9262
32 Italy 38 7,757 0.46 93.08 0.0046 0.9308
33 Pakistan 38 7,795 0.46 93.53 0.0046 0.9353
34 Trinidad and Tobago 35 7,830 0.42 93.95 0.0042 0.9395
35 Saudi Arabia 28 7,858 0.34 94.29 0.0034 0.9429
36 Peru 26 7,884 0.31 94.60 0.0031 0.9460
37 Vietnam 26 7,910 0.31 94.91 0.0031 0.9491
38 Qatar 25 7,935 0.30 95.21 0.0030 0.9521
39 Denmark 23 7,958 0.28 95.49 0.0028 0.9549
40 Turkmenistan 23 7,981 0.28 95.76 0.0028 0.9576
41 Azerbaijan 22 8,003 0.26 96.03 0.0026 0.9603
42 Tanzania 22 8,025 0.26 96.29 0.0026 0.9629
43 Guyana 19 8,044 0.23 96.52 0.0023 0.9652
44 Mozambique 17 8,061 0.20 96.72 0.0020 0.9672
45 Ukraine 16 8,077 0.19 96.92 0.0019 0.9692
46 Ireland 15 8,092 0.18 97.10 0.0018 0.9710
47 Brunei 14 8,106 0.17 97.26 0.0017 0.9726
48 Israel 14 8,120 0.17 97.43 0.0017 0.9743
49 Kuwait 14 8,134 0.17 97.60 0.0017 0.9760
50 Republic of the Congo 14 8,148 0.17 97.77 0.0017 0.9777
51 Bolivia 11 8,159 0.13 97.90 0.0013 0.9790
52 Chad 10 8,169 0.12 98.02 0.0012 0.9802
53 Cuba 10 8,179 0.12 98.14 0.0012 0.9814
54 Syria 8 8,187 0.10 98.24 0.0010 0.9824
55 Bangladesh 7 8,194 0.08 98.32 0.0008 0.9832
56 New Zealand 7 8,201 0.08 98.40 0.0008 0.9840
57 Barbados 6 8,207 0.07 98.48 0.0007 0.9848
58 Kuwait-Saudi Arabia 6 8,213 0.07 98.55 0.0007 0.9855
59 Myanmar 6 8,219 0.07 98.62 0.0007 0.9862
60 Türkiye 6 8,225 0.07 98.69 0.0007 0.9869
61 Cyprus 5 8,230 0.06 98.75 0.0006 0.9875
62 Côte d'Ivoire 5 8,235 0.06 98.81 0.0006 0.9881
63 Ethiopia 5 8,240 0.06 98.87 0.0006 0.9887
64 Namibia 5 8,245 0.06 98.93 0.0006 0.9893
65 Papua New Guinea 5 8,250 0.06 98.99 0.0006 0.9899
66 South Sudan 5 8,255 0.06 99.05 0.0006 0.9905
67 Suriname 5 8,260 0.06 99.11 0.0006 0.9911
68 Tunisia 5 8,265 0.06 99.17 0.0006 0.9917
69 Cameroon 4 8,269 0.05 99.22 0.0005 0.9922
70 Ghana 4 8,273 0.05 99.27 0.0005 0.9927
71 Guatemala 4 8,277 0.05 99.32 0.0005 0.9932
72 Mauritania 4 8,281 0.05 99.36 0.0005 0.9936
73 South Africa 4 8,285 0.05 99.41 0.0005 0.9941
74 Austria 3 8,288 0.04 99.45 0.0004 0.9945
75 Iran-Iraq 3 8,291 0.04 99.48 0.0004 0.9948
76 Senegal 3 8,294 0.04 99.52 0.0004 0.9952
77 Uganda 3 8,297 0.04 99.56 0.0004 0.9956
78 Bahrain 2 8,299 0.02 99.58 0.0002 0.9958
79 France 2 8,301 0.02 99.60 0.0002 0.9960
80 Gabon 2 8,303 0.02 99.63 0.0002 0.9963
81 Hungary 2 8,305 0.02 99.65 0.0002 0.9965
82 Kenya 2 8,307 0.02 99.68 0.0002 0.9968
83 Kuwait-Saudi Arabia-Iran 2 8,309 0.02 99.70 0.0002 0.9970
84 Philippines 2 8,311 0.02 99.72 0.0002 0.9972
85 Russia-Kazakhstan 2 8,313 0.02 99.75 0.0002 0.9975
86 Thailand-Malaysia 2 8,315 0.02 99.77 0.0002 0.9977
87 Timor-Leste 2 8,317 0.02 99.80 0.0002 0.9980
88 Albania 1 8,318 0.01 99.81 0.0001 0.9981
89 Chile 1 8,319 0.01 99.82 0.0001 0.9982
90 China-Japan 1 8,320 0.01 99.83 0.0001 0.9983
91 Grenada 1 8,321 0.01 99.84 0.0001 0.9984
92 Jamaica 1 8,322 0.01 99.86 0.0001 0.9986
93 Japan 1 8,323 0.01 99.87 0.0001 0.9987
94 Madagascar 1 8,324 0.01 99.88 0.0001 0.9988
95 Morocco 1 8,325 0.01 99.89 0.0001 0.9989
96 Palestine 1 8,326 0.01 99.90 0.0001 0.9990
97 Saudi Arabia-Bahrain 1 8,327 0.01 99.92 0.0001 0.9992
98 Saudi Arabia-Iran 1 8,328 0.01 99.93 0.0001 0.9993
99 Senegal-Mauritania 1 8,329 0.01 99.94 0.0001 0.9994
100 Spain 1 8,330 0.01 99.95 0.0001 0.9995
101 Timor Gap 1 8,331 0.01 99.96 0.0001 0.9996
102 United Arab Emirates-Iran 1 8,332 0.01 99.98 0.0001 0.9998
103 Vietnam-Malaysia 1 8,333 0.01 99.99 0.0001 0.9999
104 Zimbabwe 1 8,334 0.01 100.00 0.0001 1.0000
Total — — 8,334 — 100.00 — 1.0000 —
Autor: Grupo 5

4.2 Por Continente

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("**Local (nᵢ)**"),
    Ni      = md("**Global (Nᵢ)**"),
    hi_pct  = md("**Local (hᵢ %)**"),
    Hi_pct  = md("**Global (Hᵢ %)**"),
    hi_prop = md("**Local (hᵢ)**"),
    Hi_prop = md("**Global (Hᵢ)**")
  ) %>%
  tab_spanner(label = md("**Frecuencia absoluta**"),
              columns = c(ni, Ni)) %>%
  tab_spanner(label = md("**Frecuencia relativa (%)**"),
              columns = c(hi_pct, Hi_pct)) %>%
  tab_spanner(label = md("**Frecuencia relativa (proporción)**"),
              columns = c(hi_prop, Hi_prop)) %>%
  fmt_number(columns = c(ni, Ni),           decimals = 0, use_seps = TRUE) %>%
  fmt_number(columns = c(hi_pct, Hi_pct),   decimals = 2) %>%
  fmt_number(columns = c(hi_prop, 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(90),
    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
Frecuencia absoluta
Frecuencia relativa (%)
Frecuencia relativa (proporción)
Local (nᵢ) Global (Nᵢ) Local (hᵢ %) Global (Hᵢ %) Local (hᵢ) Global (Hᵢ)
1 América del Norte 4,468 4,468 53.61 53.61 0.5361 0.5361
2 Europa y Rusia 1,207 5,675 14.48 68.09 0.1448 0.6809
3 América del Sur y Caribe 926 6,601 11.11 79.21 0.1111 0.7921
4 Asia Pacífico y Oceanía 645 7,246 7.74 86.95 0.0774 0.8695
5 África 630 7,876 7.56 94.50 0.0756 0.9450
6 Oriente Medio 331 8,207 3.97 98.48 0.0397 0.9848
7 Asia Central y Cáucaso 92 8,299 1.10 99.58 0.0110 0.9958
8 Otro/No especificado 35 8,334 0.42 100.00 0.0042 1.0000
Total — — 8,334 — 100.00 — 1.0000 —
Autor: Grupo 5

5 Gráficos de Distribución de Freciencia

## ── Datos para graficar ───────────────────────────────────────────────────────

cont_graf <- tabla_freq_cont %>%
  mutate(Continente = fct_reorder(Continente, ni))

## ── 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)
  )

5.1 Análisis por Continente

## Continentes en el orden de la tabla (de mayor a menor) para las frecuencias acumuladas
cont_fr <- tabla_freq_cont %>%
  mutate(Continente = factor(Continente, levels = Continente))

5.1.1 Diagrama de Barras — Frecuencia Absoluta Local (nᵢ)

ggplot(cont_fr, 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: Frecuencia absoluta local (nᵢ) por continente",
       x = "Continente", y = "Frecuencia absoluta local (nᵢ)",
       caption = pie_label) +
  tema_base

5.1.2 Diagrama de Barras — Frecuencia Absoluta Global (Nᵢ)

ggplot(cont_fr, 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. 5: Frecuencia absoluta global (Nᵢ) por continente",
       x = "Continente", y = "Frecuencia absoluta global (Nᵢ)",
       caption = pie_label) +
  tema_base

5.1.3 Diagrama de Barras — Frecuencia Relativa Local (hᵢ %)

ggplot(cont_fr, 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: Frecuencia relativa local (hᵢ %) por continente",
       x = "Continente", y = "Frecuencia relativa local (%)",
       caption = pie_label) +
  tema_base

5.1.4 Diagrama de Barras — Frecuencia Relativa Global (Hᵢ %)

ggplot(cont_fr, 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. 7: Frecuencia relativa global (Hᵢ %) por continente",
       x = "Continente", y = "Frecuencia relativa global (%)",
       caption = pie_label) +
  tema_base

Diagrama Circular

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)
  )

6 Indicadores Estadísticos

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

7 Conclusiones

El valor más frecuente de “país” es “United States”. A nivel continental el valor más frecuente es América del Norte.