datos_originales <- readr::read_delim(
ruta, delim=delimitador, trim_ws=TRUE, show_col_types=FALSE,
name_repair="minimal", col_types=readr::cols(.default=readr::col_character())
)
## Carga exitosa: 47.501 registros.
codigo_limpio <- datos_originales |>
dplyr::transmute(Codigo=stringr::str_trim(as.character(.data[[columna_codigo]]))) |>
dplyr::filter(!is.na(Codigo), Codigo != "",
!toupper(Codigo) %in% c("NA", "N/A", "NULL"))
N <- nrow(codigo_limpio)
if (N == 0L) stop("No hay registros válidos de CONFIDENTIALITY_CODE.")
k_codigos <- dplyr::n_distinct(codigo_limpio$Codigo)
cat("Registros válidos:", fmt_entero(N),
" | Códigos de confidencialidad distintos:", fmt_entero(k_codigos), "\n")
## Registros válidos: 47.417 | Códigos de confidencialidad distintos: 4
| VARIABLE | TIPO | ESCALA DE MEDICIÓN | UNIDAD DE ANÁLISIS | CATEGORÍAS (k) | REGISTROS VÁLIDOS (N) |
|---|---|---|---|---|---|
| CONFIDENTIALITY_CODE (Código de confidencialidad) | Cualitativa nominal | Nominal | Pozo regulado | 4 | 47.417 |
cat(crear_cuadro(tabla_frecuencias, 1,
"Distribución de frecuencias de los pozos regulados según el código de confidencialidad, Nueva York, 1860 - 2026",
desplazamiento=(k_codigos > 15L)))
| CÓDIGO DE CONFIDENCIALIDAD | FRECUENCIA ABSOLUTA (nᵢ) | FRECUENCIA RELATIVA (hᵢ) | FRECUENCIA RELATIVA PORCENTUAL (%) |
|---|---|---|---|
| Application Received or Permit Issued | 1.483 | 0.0313 | 3.13% |
| Released | 7.640 | 0.1611 | 16.11% |
| Pre-1989 Well (N/A) | 38.258 | 0.8068 | 80.68% |
| Initial 6-month Period | 36 | 0.0008 | 0.08% |
| TOTAL | 47.417 | 1.0000 | 100.00% |
Fuente: Oil, Gas & Other Regulated Wells: Beginning 1860.
if (usar_resumen) {
cat("## Top ", numero_top, " códigos de confidencialidad con mayor frecuencia {-}\n\n", sep="")
cat("El Cuadro N° 2 presenta los ", numero_top,
" códigos de confidencialidad más frecuentes, ordenados de mayor a menor, ",
"y agrupa los restantes en «Otros códigos de confidencialidad». ",
"El Top ", numero_top, " representa el ", sprintf("%.2f%%", pct_top),
" de los ", fmt_entero(N), " registros válidos.\n\n", sep="")
cat(crear_cuadro(tabla_resumen, 2,
paste0("Distribución de frecuencias de los pozos regulados: Top ", numero_top,
" códigos de confidencialidad y Otros, Nueva York, 1860 - 2026")))
}
ggplot2::ggplot(tabla_local, ggplot2::aes(x=Codigo,y=ni,fill=Codigo)) +
ggplot2::geom_col(width=.72,color="#244861",linewidth=.36) +
ggplot2::geom_text(ggplot2::aes(label=fmt_entero(ni)),vjust=-.48,
size=4.5,fontface="bold",color="#15364C") +
ggplot2::scale_fill_manual(values=colores) +
escala_codigos +
ggplot2::scale_y_continuous(limits=c(0,limite_ni_local),
labels=fmt_entero,
expand=ggplot2::expansion(mult=c(0,0))) +
ggplot2::coord_cartesian(clip="off") +
ggplot2::labs(title="Gráfica N° 1: Frecuencia absoluta (nᵢ) local",
x="Código de confidencialidad",y="Frecuencia absoluta (nᵢ)",caption=fuente_graficas) +
tema_barras
ggplot2::ggplot(tabla_global, ggplot2::aes(x=Codigo,y=ni)) +
ggplot2::geom_col(fill="#286492",color="#244861",width=.72,linewidth=.36) +
ggplot2::geom_text(ggplot2::aes(label=fmt_entero(ni)),vjust=-.48,
size=4.5,fontface="bold",color="#15364C") +
escala_codigos +
ggplot2::scale_y_continuous(limits=c(0,limite_ni_global),
labels=fmt_entero,
expand=ggplot2::expansion(mult=c(0,0))) +
ggplot2::coord_cartesian(clip="off") +
ggplot2::labs(title="Gráfica N° 2: Frecuencia absoluta (nᵢ) global",
x="Código de confidencialidad",y="Frecuencia absoluta (nᵢ)",caption=fuente_graficas) +
tema_barras
ggplot2::ggplot(tabla_local, ggplot2::aes(x=Codigo,y=hi,fill=Codigo)) +
ggplot2::geom_col(width=.72,color="#244861",linewidth=.36) +
ggplot2::geom_text(ggplot2::aes(label=sprintf("%.2f%%",100*hi)),vjust=-.48,
size=4.3,fontface="bold",color="#15364C") +
ggplot2::scale_fill_manual(values=colores) +
escala_codigos +
ggplot2::scale_y_continuous(limits=c(0,limite_hi_local),labels=etiqueta_pct,
expand=ggplot2::expansion(mult=c(0,0))) +
ggplot2::coord_cartesian(clip="off") +
ggplot2::labs(title="Gráfica N° 3: Frecuencia relativa (hᵢ) local",
x="Código de confidencialidad",y="Frecuencia relativa (%)",caption=fuente_graficas) +
tema_barras
ggplot2::ggplot(tabla_global, ggplot2::aes(x=Codigo,y=hi)) +
ggplot2::geom_col(fill="#286492",color="#244861",width=.72,linewidth=.36) +
ggplot2::geom_text(ggplot2::aes(label=sprintf("%.2f%%",100*hi)),vjust=-.48,
size=4.3,fontface="bold",color="#15364C") +
escala_codigos +
ggplot2::scale_y_continuous(limits=c(0,limite_hi_global),
breaks=seq(0,1,by=.2),labels=etiqueta_pct,
expand=ggplot2::expansion(mult=c(0,0))) +
ggplot2::coord_cartesian(clip="off") +
ggplot2::labs(title="Gráfica N° 4: Frecuencia relativa (hᵢ) global",
x="Código de confidencialidad",y="Frecuencia relativa (%)",caption=fuente_graficas) +
tema_barras
leyenda_df <- tabla_local |>
dplyr::mutate(
etiqueta_leyenda = paste0(
stringr::str_wrap(as.character(Codigo), width = 24),
"\n",
sprintf("n = %s | %.2f%%", fmt_entero(ni), porcentaje)
)
)
valores_colores <- colores[as.character(leyenda_df$Codigo)]
labels_leyenda <- leyenda_df$etiqueta_leyenda
names(labels_leyenda) <- as.character(leyenda_df$Codigo)
ggplot2::ggplot(leyenda_df, ggplot2::aes(x = 1, y = ni, fill = Codigo)) +
ggplot2::geom_col(width = 1, color = "#244861", linewidth = .48) +
ggplot2::coord_polar(theta = "y", start = 0) +
ggplot2::scale_fill_manual(
values = valores_colores,
breaks = as.character(leyenda_df$Codigo),
labels = labels_leyenda,
drop = FALSE
) +
ggplot2::guides(fill = ggplot2::guide_legend(ncol = 1, byrow = TRUE)) +
ggplot2::labs(
title = "Gráfica N° 5: Distribución porcentual según el código de confidencialidad",
fill = "Código de confidencialidad\nFrecuencia y porcentaje",
caption = fuente_graficas
) +
ggplot2::theme_void(base_size = 15) +
ggplot2::theme(
plot.title = ggplot2::element_text(hjust = .5, face = "bold", size = 17, color = "#15364C"),
plot.subtitle = ggplot2::element_text(hjust = .5, size = 12, color = "#49657A",
margin = ggplot2::margin(t = 7, b = 12)),
legend.position = "right",
legend.title = ggplot2::element_text(face = "bold", size = 12.5, color = "#15364C", lineheight = 1.05),
legend.text = ggplot2::element_text(size = 11.2, color = "#253B4B", lineheight = 1.02),
legend.key.size = grid::unit(.62, "cm"),
legend.spacing.y = grid::unit(.12, "cm"),
plot.caption = ggplot2::element_text(hjust = 0, face = "italic", size = 10.5,
color = "#546775", margin = ggplot2::margin(t = 14)),
plot.margin = ggplot2::margin(18, 30, 25, 24)
)
cat(crear_indicadores())
| VARIABLE ANALIZADA | Media (X̄) | Mediana (Me) | Moda (Mo) | Desviación estándar (Sd) | Coeficiente de variación (CV %) | Asimetría (As) | Curtosis (K) | Valores atípicos (Outliers) |
|---|---|---|---|---|---|---|---|---|
| CONFIDENTIALITY_CODE (Código de confidencialidad) | N/A | N/A | Pre-1989 Well (N/A) | N/A | N/A | N/A | N/A | N/A |
N/A: No aplicable a una variable cualitativa nominal.
Registros válidos (N): 47.417 | Categorías: 4 | Frecuencia modal: 38.258 | Porcentaje modal: 80.68%.
Fuente: Oil, Gas & Other Regulated Wells: Beginning 1860.
La variable CONFIDENTIALITY_CODE (Código de confidencialidad) es cualitativa nominal y presenta 4 categorías en 47.417 registros válidos. La moda corresponde a Pre-1989 Well (N/A), con una frecuencia de 38.258 pozos (80.68% del total), lo que evidencia una mayor concentración de registros en determinados códigos de confidencialidad de los pozos del estado de Nueva York.
Autor: Jennifer Cordones | Análisis Estadístico — Oil, Gas & Other Regulated Wells - NY State