library(readxl)
library(dplyr)
library(gt)
library(ggplot2)
library(scales)
library(forcats)
datos <- read_excel("dataset_mundial_petro.xlsx")
n <- nrow(datos)
cat("Número de registros:", n, "\n")
## Número de registros: 8334
cat("Número de variables:", ncol(datos), "\n")
## Número de variables: 23
En esta sección se cargan las librerías necesarias y se importa 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.
Se extrae la variable Location accuracy (Precisión de Ubicación) del dataset y se realiza el conteo inicial de registros por categoría. Esta variable es de escala ordinal, ya que sus categorías presentan un orden lógico de menor a mayor precisión geográfica.
conteo_inicial <- datos %>%
count(`Location accuracy`, name = "fi") %>%
arrange(desc(fi))
k <- nrow(conteo_inicial)
cat("Total de categorías:", k, "\n")
## Total de categorías: 3
cat("Categoría más frecuente:", conteo_inicial$`Location accuracy`[1],
"con", conteo_inicial$fi[1], "registros\n")
## Categoría más frecuente: exact con 6353 registros
cat("Categoría menos frecuente:", conteo_inicial$`Location accuracy`[k],
"con", conteo_inicial$fi[k], "registro(s)\n")
## Categoría menos frecuente: NA con 796 registro(s)
Vista previa del conteo:
head(conteo_inicial, 2)
## # A tibble: 2 × 2
## `Location accuracy` fi
## <chr> <int>
## 1 exact 6353
## 2 approximate 1185
Dado que Location accuracy es una variable cualitativa ordinal, se organiza según el orden lógico de precisión geográfica: de menor a mayor exactitud en el registro de la ubicación.
tabla_freq <- conteo_inicial %>%
mutate(
`Location accuracy` = recode(`Location accuracy`,
"exact" = "Exacta",
"approximate" = "Aproximada"
),
hi_prop = fi / n,
hi_pct = hi_prop * 100
) %>%
mutate(i = row_number()) %>%
select(i, `Location accuracy`, fi, hi_pct, hi_prop)
cat("Verificación — suma de fi:", sum(tabla_freq$fi), "\n")
## Verificación — suma de fi: 8334
cat("Verificación — suma de hi (%):", round(sum(tabla_freq$hi_pct), 2), "(debe ser 100)\n")
## Verificación — suma de hi (%): 100 (debe ser 100)
tabla_freq %>%
gt() %>%
tab_header(
title = md("**Tabla N° 2**"),
subtitle = md("Agrupación por precisión de ubicación de yacimientos de extracción de petróleo y gas")
) %>%
cols_label(
i = md("**N°**"),
`Location accuracy` = md("**Precisión de Ubicación**"),
fi = md("**ni**"),
hi_pct = md("**(%)** "),
hi_prop = md("**(proporción)**")
) %>%
tab_spanner(
label = md("**hi**"),
columns = c(hi_pct, hi_prop)
) %>%
fmt_number(columns = hi_pct, decimals = 2) %>%
fmt_number(columns = hi_prop, decimals = 3) %>%
fmt_number(columns = fi, decimals = 0, use_seps = TRUE) %>%
grand_summary_rows(
columns = c(fi, hi_pct, hi_prop),
fns = list(label = "Total", fn = "sum"),
fmt = list(
~ fmt_number(., columns = fi, decimals = 0),
~ fmt_number(., columns = hi_pct, decimals = 2),
~ fmt_number(., columns = hi_prop, decimals = 3)
)
) %>%
cols_hide(columns = i) %>%
tab_source_note(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",
heading.border.bottom.color = "#AAAAAA",
heading.border.bottom.width = px(1),
column_labels.font.weight = "bold",
column_labels.background.color = "#FFFFFF",
column_labels.border.top.color = "#AAAAAA",
column_labels.border.top.width = px(1),
column_labels.border.bottom.color = "#AAAAAA",
column_labels.border.bottom.width = px(1),
row.striping.include_table_body = FALSE,
source_notes.font.size = px(11),
source_notes.border.lr.color = "transparent",
table.border.top.color = "#AAAAAA",
table.border.top.width = px(1),
table.border.bottom.color = "#AAAAAA",
table.border.bottom.width = px(1)
) %>%
tab_style(
style = cell_text(color = "white", weight = "bold"),
locations = cells_title(groups = c("title", "subtitle"))
) %>%
tab_style(
style = cell_text(color = "#000000", weight = "bold"),
locations = cells_column_labels()
) %>%
tab_style(
style = cell_text(color = "#000000", weight = "bold"),
locations = cells_column_spanners()
) %>%
tab_style(
style = list(
cell_text(weight = "bold", color = "#000000"),
cell_borders(sides = "top", color = "#333333", weight = px(1))
),
locations = cells_grand_summary()
) %>%
tab_style(
style = cell_text(color = "#333333"),
locations = cells_body()
)
| Tabla N° 2 | ||||
| Agrupación por precisión de ubicación de yacimientos de extracción de petróleo y gas | ||||
| Precisión de Ubicación | ni |
hi
|
||
|---|---|---|---|---|
| (%) | (proporción) | |||
| Exacta | 6,353 | 76.23 | 0.762 | |
| Aproximada | 1,185 | 14.22 | 0.142 | |
| NA | 796 | 9.55 | 0.096 | |
| Total | — | 8,334 | 100.00 | 1.000 |
| Autor: Grupo 5 | ||||
tema_base <- theme_minimal(base_size = 12) +
theme(
legend.position = "none",
plot.title = element_text(face = "bold", color = "#222222", size = 13),
plot.subtitle = element_text(color = "#555555", size = 10),
plot.caption = element_text(color = "#888888", size = 9),
axis.title = element_text(face = "bold", color = "#333333"),
axis.text = element_text(color = "#333333"),
panel.grid.major.y = element_blank(),
panel.grid.major.x = element_line(color = "#EEEEEE"),
panel.grid.minor = element_blank(),
plot.background = element_rect(fill = "white", color = NA),
panel.background = element_rect(fill = "white", color = NA)
)
colores_loc <- c("#2E86C1", "#AED6F1")
loc_graf <- tabla_freq %>%
mutate(`Location accuracy` = fct_reorder(`Location accuracy`, fi))
ggplot(loc_graf, aes(x = `Location accuracy`, y = fi, fill = `Location accuracy`)) +
geom_col(width = 0.65, color = "white", linewidth = 0.3) +
geom_text(
aes(label = format(fi, big.mark = ",")),
hjust = -0.1, size = 3.4, color = "#222222", fontface = "bold"
) +
coord_flip() +
scale_fill_manual(values = colores_loc) +
scale_y_continuous(
labels = label_comma(),
expand = expansion(mult = c(0, 0.18))
) +
labs(
title = "Gráfica N. 1: Distribución de yacimientos de petróleo y gas por precisión de ubicación",
x = "Precisión de Ubicación",
y = "Frecuencia Absoluta (fi)",
caption = paste0("n = ", format(n, big.mark = ","), " | Fuente: Global Energy Monitor — GOGET 2023")
) +
tema_base
ggplot(loc_graf, aes(x = `Location accuracy`, y = hi_pct, fill = `Location accuracy`)) +
geom_col(width = 0.65, color = "white", linewidth = 0.3) +
geom_text(
aes(label = paste0(round(hi_pct, 2), "%")),
hjust = -0.1, size = 3.4, color = "#222222", fontface = "bold"
) +
coord_flip() +
scale_fill_manual(values = colores_loc) +
scale_y_continuous(
labels = function(x) paste0(x, "%"),
expand = expansion(mult = c(0, 0.18))
) +
labs(
title = "Gráfica N. 2: Distribución porcentual de yacimientos de petróleo y gas por precisión de ubicación",
x = "Precisión de Ubicación",
y = "Frecuencia Relativa (%)",
caption = paste0("n = ", format(n, big.mark = ","), " | Fuente: Global Energy Monitor — GOGET 2023")
) +
tema_base
datos_pie <- tabla_freq %>%
arrange(desc(fi)) %>%
mutate(
`Location accuracy` = fct_reorder(`Location accuracy`, hi_pct),
etiqueta = paste0(round(hi_pct, 1), "%")
)
ggplot(datos_pie, aes(x = "", y = hi_pct, fill = `Location accuracy`)) +
geom_col(width = 1, color = "white", linewidth = 0.6) +
geom_text(
aes(label = etiqueta),
position = position_stack(vjust = 0.5),
size = 3.5, color = "#1A1A1A", fontface = "bold"
) +
coord_polar(theta = "y", start = 0) +
scale_fill_manual(values = colores_loc) +
labs(
title = "Gráfica N.3: Distribución Porcentual por Precisión de Ubicación",
fill = "Precisión de Ubicación",
caption = paste0("n = ", format(n, big.mark = ","), " | Fuente: Global Energy Monitor — GOGET 2023")
) +
theme_void(base_size = 12) +
theme(
plot.title = element_text(face = "bold", color = "#222222", size = 13, hjust = 0.5),
plot.caption = element_text(color = "#888888", size = 9),
legend.position = "right",
legend.title = element_text(face = "bold", color = "#222222"),
legend.text = element_text(size = 9, color = "#333333"),
plot.background = element_rect(fill = "white", color = NA)
)
moda_loc <- tabla_freq$`Location accuracy`[which.max(tabla_freq$fi)]
tabla_indicadores <- data.frame(
"Variable" = "Location accuracy",
"Rango" = "Precisión de Ubicación",
"Media (X)" = "-",
"Mediana (Me)" = "-",
"Moda (Mo)" = moda_loc,
"Varianza (V)" = "-",
"Desv. Est. (Sd)" = "-",
"C.V. (%)" = "-",
"Asimetría (As)" = "-",
"Curtosis (K)" = "-",
check.names = FALSE
)
tabla_indicadores %>%
gt() %>%
tab_header(
title = md("**Tabla N°3 de Conclusiones yacimientos de petróleo y gas por Precisión de Ubicación**")
) %>%
tab_source_note(source_note = "Autor: Grupo 5") %>%
tab_options(
table.width = pct(92),
table.font.size = px(13),
table.font.names = "Arial",
heading.title.font.size = px(15),
heading.align = "left",
heading.border.bottom.color = "#CCCCCC",
heading.border.bottom.width = px(1),
column_labels.font.weight = "bold",
column_labels.background.color = "#F0F0F0",
column_labels.border.top.color = "#AAAAAA",
column_labels.border.top.width = px(1),
column_labels.border.bottom.color = "#AAAAAA",
column_labels.border.bottom.width = px(1),
row.striping.include_table_body = FALSE,
source_notes.font.size = px(11),
source_notes.border.lr.color = "transparent",
table.border.top.color = "#AAAAAA",
table.border.top.width = px(1),
table.border.bottom.color = "#AAAAAA",
table.border.bottom.width = px(2)
) %>%
tab_style(
style = cell_text(color = "#000000", weight = "bold"),
locations = cells_column_labels()
) %>%
tab_style(
style = cell_text(color = "#333333"),
locations = cells_body()
)
| Tabla N°3 de Conclusiones yacimientos de petróleo y gas por Precisión de Ubicación | |||||||||
| Variable | Rango | Media (X) | Mediana (Me) | Moda (Mo) | Varianza (V) | Desv. Est. (Sd) | C.V. (%) | Asimetría (As) | Curtosis (K) |
|---|---|---|---|---|---|---|---|---|---|
| Location accuracy | Precisión de Ubicación | - | - | Exacta | - | - | - | - | - |
| Autor: Grupo 5 | |||||||||