Preparacion del entorno de trabajo cargando los paquetes necesarios para el manejo de datos, formato de tablas y visualizacion de graficas.
library(readxl)
library(dplyr)
library(gt)
library(ggplot2)
library(scales)
library(e1071)
# Seleccion del archivo Excel (se abre ventana emergente)
ruta_archivo <- file.choose()
Datos <- read_excel(ruta_archivo)
cat("Dataset cargado exitosamente. Total de variables importadas:", ncol(Datos), "\n")
## Dataset cargado exitosamente. Total de variables importadas: 32
Se extrae y limpia la variable Latitude (Latitud
Geografica). Se aseguran los formatos numericos (reemplazando comas por
puntos) y se omiten los valores nulos para garantizar la exactitud de
los calculos.
valores_limpios <- gsub(",", ".", Datos$Latitude)
Variable <- na.omit(as.numeric(valores_limpios))
N <- length(Variable)
cat("Variable analizada: Latitude\n")
## Variable analizada: Latitude
cat("Total de observaciones utiles (n):", N, "\n")
## Total de observaciones utiles (n): 7537
cat("Minimo:", round(min(Variable), 4), "\n")
## Minimo: -53.9713
cat("Maximo:", round(max(Variable), 4), "\n")
## Maximo: 73.4344
Se realiza el calculo de intervalos y el conteo de frecuencias usando la regla de Sturges. Se genera una distribucion con limites ajustados a multiplos de 10 (enteros) para facilitar la interpretacion geografica.
BASE <- 10
min_int <- floor(min(Variable) / BASE) * BASE
max_int <- ceiling(max(Variable) / BASE) * BASE
k_int_sug <- floor(1 + 3.322 * log10(N))
Rango_int <- max_int - min_int
Amplitud_int <- ceiling((Rango_int / k_int_sug) / 10) * 10
if (Amplitud_int == 0) Amplitud_int <- 10
cortes_int <- seq(from = min_int, by = Amplitud_int, length.out = k_int_sug + 1)
if (max(cortes_int) < max(Variable)) cortes_int <- c(cortes_int, max(cortes_int) + Amplitud_int)
while (length(cortes_int) > 2 && cortes_int[length(cortes_int) - 1] >= max(Variable)) {
cortes_int <- cortes_int[-length(cortes_int)]
}
K_real <- length(cortes_int) - 1
inter_int <- cut(Variable, breaks = cortes_int, include.lowest = TRUE, right = FALSE)
ni_int <- as.vector(table(inter_int))
# Calculos unitarios y porcentuales
hi_int_unit <- ni_int / N
hi_int_perc <- hi_int_unit * 100
TDF_Enteros <- data.frame(
Li = cortes_int[1:K_real],
Ls = cortes_int[2:(K_real + 1)],
MC = (cortes_int[1:K_real] + cortes_int[2:(K_real + 1)]) / 2,
ni = ni_int,
hi_unit = hi_int_unit,
hi_perc = hi_int_perc,
Ni_asc = cumsum(ni_int),
Ni_desc = rev(cumsum(rev(ni_int))),
Hi_asc_unit = cumsum(hi_int_unit),
Hi_desc_unit = rev(cumsum(rev(hi_int_unit))),
Hi_asc_perc = cumsum(hi_int_perc),
Hi_desc_perc = rev(cumsum(rev(hi_int_perc)))
)
cat("Clases enteras ajustadas (k):", K_real, "\n")
## Clases enteras ajustadas (k): 7
Se estructura la matriz de resultados para visualizar la concentracion geografica. Esta tabla incluye las frecuencias relativas en formato unitario (\(h_i\)) y porcentual (%).
fuente_nota <- paste("n =", format(N, big.mark = ","), "| Fuente: Global Energy Monitor - GOGET 2023")
TDF_Int_gt <- TDF_Enteros
fila_total_int <- data.frame(
Li = NA, Ls = NA, MC = NA,
ni = sum(TDF_Int_gt$ni),
hi_unit = sum(TDF_Int_gt$hi_unit),
hi_perc = sum(TDF_Int_gt$hi_perc),
Ni_asc = NA, Ni_desc = NA,
Hi_asc_unit = NA, Hi_desc_unit = NA,
Hi_asc_perc = NA, Hi_desc_perc = NA
)
bind_rows(TDF_Int_gt, fila_total_int) %>%
gt() %>%
tab_header(
title = md("**Tabla N°1**"),
subtitle = "Distribucion de frecuencias de latitud geografica (Limites enteros)"
) %>%
cols_label(
Li = "Lim. Inf (°)", Ls = "Lim. Sup (°)",
MC = "Marca clase", ni = md("n~i~"),
hi_unit = md("h~i~ (Unit)"), hi_perc = md("h~i~ (%)"),
Ni_asc = md("N~i~ (\u2191)"), Ni_desc = md("N~i~ (\u2193)"),
Hi_asc_unit = md("H~i~ (Unit \u2191)"), Hi_desc_unit = md("H~i~ (Unit \u2193)"),
Hi_asc_perc = md("H~i~ (% \u2191)"), Hi_desc_perc = md("H~i~ (% \u2193)")
) %>%
cols_align(align = "center", columns = everything()) %>%
fmt_number(columns = c(Li, Ls, MC, hi_perc, Hi_asc_perc, Hi_desc_perc), decimals = 2) %>%
fmt_number(columns = c(hi_unit, Hi_asc_unit, Hi_desc_unit), decimals = 4) %>%
fmt_number(columns = c(ni, Ni_asc, Ni_desc), decimals = 0, use_seps = TRUE) %>%
tab_source_note(fuente_nota) %>%
tab_style(
style = cell_fill(color = "#F5F5F5"),
locations = cells_body(rows = nrow(TDF_Int_gt) + 1)
) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_body(rows = nrow(TDF_Int_gt) + 1)
) %>%
sub_missing(columns = everything(), missing_text = "") %>%
tab_options(heading.background.color = "#EBF5FB", column_labels.font.weight = "bold")
| Tabla N°1 | |||||||||||
| Distribucion de frecuencias de latitud geografica (Limites enteros) | |||||||||||
| Lim. Inf (°) | Lim. Sup (°) | Marca clase | ni | hi (Unit) | hi (%) | Ni (↑) | Ni (↓) | Hi (Unit ↑) | Hi (Unit ↓) | Hi (% ↑) | Hi (% ↓) |
|---|---|---|---|---|---|---|---|---|---|---|---|
| −60.00 | −40.00 | −50.00 | 79 | 0.0105 | 1.05 | 79 | 7,537 | 0.0105 | 1.0000 | 1.05 | 100.00 |
| −40.00 | −20.00 | −30.00 | 248 | 0.0329 | 3.29 | 327 | 7,458 | 0.0434 | 0.9895 | 4.34 | 98.95 |
| −20.00 | 0.00 | −10.00 | 309 | 0.0410 | 4.10 | 636 | 7,210 | 0.0844 | 0.9566 | 8.44 | 95.66 |
| 0.00 | 20.00 | 10.00 | 956 | 0.1268 | 12.68 | 1,592 | 6,901 | 0.2112 | 0.9156 | 21.12 | 91.56 |
| 20.00 | 40.00 | 30.00 | 2,971 | 0.3942 | 39.42 | 4,563 | 5,945 | 0.6054 | 0.7888 | 60.54 | 78.88 |
| 40.00 | 60.00 | 50.00 | 2,666 | 0.3537 | 35.37 | 7,229 | 2,974 | 0.9591 | 0.3946 | 95.91 | 39.46 |
| 60.00 | 80.00 | 70.00 | 308 | 0.0409 | 4.09 | 7,537 | 308 | 1.0000 | 0.0409 | 100.00 | 4.09 |
| 7,537 | 1.0000 | 100.00 | |||||||||
| n = 7,537 | Fuente: Global Energy Monitor - GOGET 2023 | |||||||||||
color_barras <- "#2E86C1"
color_ojiva1 <- "#2E86C1"
color_ojiva2 <- "#C03928"
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(angle = 25, hjust = 1, size = 10),
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)
)
df_graf <- TDF_Enteros %>%
mutate(intervalo = factor(paste(Li, "-", Ls), levels = paste(Li, "-", Ls)))
ggplot(df_graf, aes(x = intervalo, y = ni)) +
geom_col(fill = color_barras, color = "white", width = 0.95) +
geom_text(aes(label = format(ni, big.mark = ",")), vjust = -0.4, size = 3.5, fontface = "bold") +
scale_y_continuous(labels = label_comma(), expand = expansion(mult = c(0, 0.12))) +
labs(title = "Histograma de Frecuencia Absoluta",
x = "Latitud (°)", y = "Frecuencia Absoluta (ni)",
caption = fuente_nota) +
tema_base
ggplot(df_graf, aes(x = intervalo, y = hi_perc)) +
geom_col(fill = color_barras, color = "white", width = 0.95) +
geom_text(aes(label = paste0(round(hi_perc, 2), "%")), vjust = -0.4, size = 3.5, fontface = "bold") +
scale_y_continuous(labels = function(x) paste0(x, "%"), expand = expansion(mult = c(0, 0.12))) +
labs(title = "Histograma de Frecuencia Relativa Porcentual",
x = "Latitud (°)", y = "Frecuencia Relativa (%)",
caption = fuente_nota) +
tema_base
ggplot(data.frame(x = Variable), aes(x = x)) +
geom_boxplot(fill = color_barras, color = "#1A5276", outlier.color = "#C03928", outlier.size = 1.5) +
labs(title = "Diagrama de Cajas (Boxplot)",
x = "Latitud (°)", y = "",
caption = fuente_nota) +
theme_minimal(base_size = 12) +
theme(
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
plot.title = element_text(face = "bold", size = 13),
plot.caption = element_text(color = "#888888", size = 9, hjust = 0),
plot.background = element_rect(fill = "white", color = NA)
)
ojiva_df <- data.frame(
x = c(TDF_Enteros$Ls, TDF_Enteros$Li),
y = c(TDF_Enteros$Hi_asc_perc, TDF_Enteros$Hi_desc_perc),
tipo = rep(c("Ascendente", "Descendente"), each = K_real)
)
ggplot(ojiva_df, aes(x = x, y = y, color = tipo, group = tipo)) +
geom_line(linewidth = 1.2) +
geom_point(size = 2.5) +
scale_color_manual(values = c("Ascendente" = color_ojiva1, "Descendente" = color_ojiva2)) +
scale_y_continuous(labels = function(x) paste0(x, "%"), limits = c(0, 105), expand = expansion(mult = c(0, 0))) +
labs(title = "Ojivas Ascendente y Descendente",
x = "Latitud (°)", y = "Frecuencia Acumulada (%)",
color = NULL, caption = fuente_nota) +
theme_minimal(base_size = 12) +
theme(
plot.title = element_text(face = "bold", size = 13),
plot.caption = element_text(color = "#888888", size = 9, hjust = 0),
legend.position = "bottom",
plot.background = element_rect(fill = "white", color = NA)
)
La variable Latitud es cuantitativa continua de escala de razon, por lo que se calculan todos los indicadores: tendencia central, dispersion, forma y valores atipicos.
media <- mean(Variable)
mediana <- median(Variable)
moda_val <- TDF_Enteros$MC[which.max(TDF_Enteros$ni)]
varianza <- var(Variable)
sd_val <- sd(Variable)
CV <- (sd_val / abs(media)) * 100
asim <- skewness(Variable, type = 2)
kurt <- kurtosis(Variable)
Q1 <- quantile(Variable, 0.25)
Q3 <- quantile(Variable, 0.75)
IQR_val <- Q3 - Q1
outliers_data <- Variable[Variable < (Q1 - 1.5 * IQR_val) | Variable > (Q3 + 1.5 * IQR_val)]
num_out <- length(outliers_data)
out_txt <- if (num_out > 0) {
paste0(num_out, " [", round(min(outliers_data), 2), "; ", round(max(outliers_data), 2), "]")
} else {
"0 [Sin outliers]"
}
data.frame(
Variable = "Latitud (°)",
Rango = paste0("[", round(min(Variable), 2), "; ", round(max(Variable), 2), "]"),
Media = round(media, 2),
Mediana = round(mediana, 2),
Moda = round(moda_val, 2),
Varianza = round(varianza, 2),
Desv_Est = round(sd_val, 2),
CV = round(CV, 2),
Asimetria = round(asim, 4),
Curtosis = round(kurt, 4),
Outliers = out_txt,
check.names = FALSE
) %>%
gt() %>%
tab_header(title = md("**Tabla N°2: Indicadores Estadisticos de Latitud**")) %>%
cols_label(
Variable = "Variable",
Rango = "Rango",
Media = md("Media (X\u0304)"),
Mediana = "Mediana (Me)",
Moda = "Moda (Mo)",
Varianza = md("Varianza (S\u00B2)"),
Desv_Est = "Desv. Est. (S)",
CV = "C.V. (%)",
Asimetria = "Asimetria (As)",
Curtosis = "Curtosis (K)",
Outliers = "Outliers [Intervalo]"
) %>%
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(13),
heading.background.color = "#AAAAAA",
heading.border.bottom.color = "#AAAAAA",
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"),
locations = cells_column_labels()
) %>%
tab_style(
style = cell_text(color = "#333333", align = "center"),
locations = cells_body(columns = everything())
)
| Tabla N°2: Indicadores Estadisticos de Latitud | ||||||||||
| Variable | Rango | Media (X̄) | Mediana (Me) | Moda (Mo) | Varianza (S²) | Desv. Est. (S) | C.V. (%) | Asimetria (As) | Curtosis (K) | Outliers [Intervalo] |
|---|---|---|---|---|---|---|---|---|---|---|
| Latitud (°) | [-53.97; 73.43] | 32.25 | 32.53 | 30 | 521.16 | 22.83 | 70.78 | -1.2222 | 1.6975 | 430 [-53.97; -7.66] |
| Autor: Grupo 5 | ||||||||||
Los valores de la latitud geografica de los yacimientos fluctuan entre -53.97° y 73.43° y giran en torno a 32.53° (mediana), con una desviacion estandar de 22.83, presentando 430 valores atipicos (entre -53.97° y -7.66°), siendo un conjunto de datos heterogeneo (C.V. = 70.78%), cuyos valores se agrupan medianamente en la parte alta (hemisferio norte) de la latitud. Por lo anterior, el comportamiento es perjudicial, ya que refleja una concentracion importante de yacimientos en la franja templada del hemisferio norte (entre 20° y 60°), lo que incrementa la exposicion a factores climaticos, regulatorios y geopoliticos correlacionados de esa misma region, reduciendo la diversificacion geografica del portafolio.