La variable WELL_TYPE (tipo de pozo) es cualitativa nominal: clasifica cada pozo según su tipo mediante códigos (OD, GD, NL, IW, DW, DH, …). Como tiene 20 categorías, las de menos del 1 % se agrupan en “Otros” para una visualización clara.
library(readxl)
library(dplyr)
library(gt)
col_principal <- "#0E6655"
col_barras <- "#16A085"
col_acento <- "#E67E22"
col_grid <- "#D7DBDD"
colores_pie <- c("#0E6655", "#117A65", "#16A085", "#1ABC9C", "#48C9B0",
"#76D7C4", "#A3E4D7", "#D0ECE7", "#E8F8F5", "#BFC9CA")
setwd("C:/Users/HP/Desktop/VARIABLESDALLY")
Datos <- read.csv("Oil__Gas____Other_Regulated_Wells__Beginning_1860 (4).csv",
header = TRUE, sep = ";", dec = ",")Categoria <- as.character(Datos$Well.Type)
Categoria <- Categoria[Categoria != "" & !is.na(Categoria)]
moda_cat <- names(sort(table(Categoria), decreasing = TRUE))[1]
TDF <- as.data.frame(table(Categoria), stringsAsFactors = FALSE)
colnames(TDF) <- c("Tipo", "ni")
TDF <- TDF[order(-TDF$ni), ]
umbral <- 0.01 * sum(TDF$ni)
peq <- TDF$ni < umbral
if (any(peq)) {
TDF <- rbind(TDF[!peq, ],
data.frame(Tipo = "Otros", ni = sum(TDF$ni[peq]), stringsAsFactors = FALSE))
}
TDF## Tipo ni
## 15 OD 17873
## 6 GD 10047
## 14 NL 8492
## 9 IW 4502
## 5 DW 1695
## 3 DH 1136
## 19 ST 973
## 1 BR 765
## 8 GW 658
## 11 Otros 1241
## Tipo ni hi
## 15 OD 17873 37.72
## 6 GD 10047 21.20
## 14 NL 8492 17.92
## 9 IW 4502 9.50
## 5 DW 1695 3.58
## 3 DH 1136 2.40
## 19 ST 973 2.05
## 1 BR 765 1.61
## 8 GW 658 1.39
## 11 Otros 1241 2.62
TDFcompleta <- rbind(
TDF,
data.frame(Tipo = "Total", ni = sum(TDF$ni), hi = round(sum(TDF$hi), 2))
)
TDFcompleta## Tipo ni hi
## 15 OD 17873 37.72
## 6 GD 10047 21.20
## 14 NL 8492 17.92
## 9 IW 4502 9.50
## 5 DW 1695 3.58
## 3 DH 1136 2.40
## 19 ST 973 2.05
## 1 BR 765 1.61
## 8 GW 658 1.39
## 11 Otros 1241 2.62
## 12 Total 47382 99.99
modal_row <- which(TDFcompleta$Tipo == moda_cat)
TDFcompleta %>%
gt() %>%
tab_header(
title = md("**DISTRIBUCIÓN DE FRECUENCIAS — TIPO DE POZO (WELL_TYPE)**"),
subtitle = md("Variable cualitativa nominal · Pozos de Nueva York")
) %>%
cols_label(Tipo = "Tipo de pozo", ni = "Frecuencia absoluta (ni)",
hi = "Frecuencia relativa (hi %)") %>%
fmt_number(columns = ni, decimals = 0, sep_mark = ",") %>%
fmt_number(columns = hi, decimals = 2) %>%
data_color(columns = hi, rows = Tipo != "Total",
palette = c("#E8F8F5", "#A3E4D7", "#48C9B0", "#16A085", "#0E6655")) %>%
cols_align(align = "left", columns = Tipo) %>%
cols_align(align = "center", columns = c(ni, hi)) %>%
tab_style(
style = list(cell_fill(color = col_principal), cell_text(color = "white", weight = "bold")),
locations = cells_title()) %>%
tab_style(
style = list(cell_fill(color = "#148F77"), cell_text(color = "white", weight = "bold")),
locations = cells_column_labels()) %>%
tab_style(
style = list(cell_fill(color = "#FDEBD0"), cell_text(weight = "bold")),
locations = cells_body(rows = modal_row)) %>%
tab_style(
style = list(cell_fill(color = "#D0ECE7"), cell_text(weight = "bold")),
locations = cells_body(rows = nrow(TDFcompleta))) %>%
opt_row_striping() %>%
opt_table_font(font = google_font("Roboto")) %>%
tab_options(
table.font.size = px(13), heading.align = "left",
heading.title.font.size = px(17), data_row.padding = px(8),
table.border.top.color = col_principal,
table.border.bottom.color = col_principal,
column_labels.border.bottom.color = col_principal) %>%
tab_source_note(md("*Fuente: NYS DEC — Oil, Gas & Other Regulated Wells. Elaboración: jenny.*"))| DISTRIBUCIÓN DE FRECUENCIAS — TIPO DE POZO (WELL_TYPE) | ||
| Variable cualitativa nominal · Pozos de Nueva York | ||
| Tipo de pozo | Frecuencia absoluta (ni) | Frecuencia relativa (hi %) |
|---|---|---|
| OD | 17,873 | 37.72 |
| GD | 10,047 | 21.20 |
| NL | 8,492 | 17.92 |
| IW | 4,502 | 9.50 |
| DW | 1,695 | 3.58 |
| DH | 1,136 | 2.40 |
| ST | 973 | 2.05 |
| BR | 765 | 1.61 |
| GW | 658 | 1.39 |
| Otros | 1,241 | 2.62 |
| Total | 47,382 | 99.99 |
| Fuente: NYS DEC — Oil, Gas & Other Regulated Wells. Elaboración: jenny. | ||
par(mar = c(6, 5, 4, 2))
bp <- barplot(datos$ni,
main = "Gráfica N°1: Distribución de pozos según su tipo (NY)",
ylab = "Cantidad de pozos", col = col_barras,
names.arg = datos$Tipo, las = 1, cex.names = 0.85, cex.axis = 0.8, cex.main = 0.95,
ylim = c(0, max(datos$ni) * 1.15))
text(x = bp, y = datos$ni, labels = format(datos$ni, big.mark = ","),
pos = 3, cex = 0.7, xpd = TRUE)
mtext("Tipo de pozo", side = 1, line = 3.5, cex = 0.95)par(mar = c(6, 5, 4, 2))
bp <- barplot(datos$ni,
main = "Gráfica N°2: Cantidad de pozos según su tipo (NY)",
ylab = "Cantidad de pozos", col = col_barras,
names.arg = datos$Tipo, las = 1, cex.names = 0.85, cex.axis = 0.8, cex.main = 0.95,
ylim = c(0, sum(datos$ni)))
text(x = bp, y = datos$ni, labels = format(datos$ni, big.mark = ","),
pos = 3, cex = 0.7, xpd = TRUE)
mtext("Tipo de pozo", side = 1, line = 3.5, cex = 0.95)par(mar = c(6, 5, 4, 2))
bp <- barplot(datos$hi,
main = "Gráfica N°3: Distribución porcentual de pozos según su tipo (NY)",
ylab = "Porcentaje (%)", col = col_barras,
names.arg = datos$Tipo, las = 1, cex.names = 0.85, cex.axis = 0.8, cex.main = 0.95,
ylim = c(0, max(datos$hi) * 1.15))
text(x = bp, y = datos$hi, labels = paste0(datos$hi, "%"),
pos = 3, cex = 0.7, xpd = TRUE)
mtext("Tipo de pozo", side = 1, line = 3.5, cex = 0.95)par(mar = c(6, 5, 4, 2))
bp <- barplot(datos$hi,
main = "Gráfica N°4: Distribución porcentual global de pozos según su tipo (NY)",
ylab = "Porcentaje (%)", col = col_barras,
names.arg = datos$Tipo, las = 1, cex.names = 0.85, cex.axis = 0.8, cex.main = 0.95,
ylim = c(0, 100))
text(x = bp, y = datos$hi, labels = paste0(datos$hi, "%"),
pos = 3, cex = 0.7, xpd = TRUE)
mtext("Tipo de pozo", side = 1, line = 3.5, cex = 0.95)par(mar = c(2, 5, 4, 9), xpd = TRUE)
pct <- datos$hi
pie(datos$ni, labels = "",
col = colores, border = "white", radius = 0.95,
init.angle = 90, clockwise = TRUE, cex.main = 0.95,
main = "Gráfica N°5: Distribución porcentual por tipo de pozo")
frac <- datos$ni / sum(datos$ni)
theta <- (90 - 360 * (cumsum(frac) - frac / 2)) * pi / 180
text(0.6 * cos(theta), 0.6 * sin(theta),
labels = ifelse(pct >= 4, paste0(pct, "%"), ""),
col = "white", cex = 0.8, font = 2)
peqi <- which(pct < 4)
if (length(peqi) > 0) {
ys <- seq(1.0, -0.2, length.out = length(peqi))
for (k in seq_along(peqi)) {
i <- peqi[k]
x0 <- 0.95 * cos(theta[i]); y0 <- 0.95 * sin(theta[i])
segments(x0, y0, -1.08, ys[k], col = "gray55", lwd = 1)
et <- paste0(pct[i], "%")
w <- strwidth(et, cex = 0.62) + 0.06; h <- strheight(et, cex = 0.62) + 0.08
rect(-1.08 - w, ys[k] - h / 2, -1.08, ys[k] + h / 2, col = "white", border = "gray55")
text(-1.08 - w / 2, ys[k], et, cex = 0.62, font = 2, col = "#0E6655")
}
}
legend(x = 1.05, y = 0.9,
legend = paste0(datos$Tipo, " (", pct, "%)"),
fill = colores, cex = 0.8, bty = "n", title = "Tipo de pozo")Por tratarse de una variable cualitativa nominal, la única medida de tendencia central aplicable es la moda (la categoría más frecuente).
Conclusiones <- data.frame(
Variable = "Tipo de pozo",
`Rango [Min; Max]` = "N/A",
`Media (X)` = "N/A",
`Mediana (Me)` = "N/A",
`Moda (Mo)` = moda_cat,
`Varianza (S2)` = "N/A",
`Desv. Est. (S)` = "N/A",
`C.V. (%)` = "N/A",
`Asimetria (As)` = "N/A",
`Curtosis (K)` = "N/A",
`Valores Atipicos` = "N/A",
check.names = FALSE
)
gt(Conclusiones) %>%
tab_header(
title = md("**CONCLUSIONES Y ESTADÍSTICOS**"),
subtitle = "Resumen de indicadores del tipo de pozo — Nueva York") %>%
tab_source_note(source_note = "Autor: DALLYANA") %>%
cols_align(align = "center", columns = everything()) %>%
tab_style(
style = list(cell_fill(color = col_principal), cell_text(color = "white", weight = "bold")),
locations = cells_title()) %>%
tab_style(
style = list(cell_fill(color = "#148F77"), cell_text(color = "white", weight = "bold")),
locations = cells_column_labels()) %>%
tab_style(
style = list(cell_fill(color = "#FDEBD0"), cell_text(weight = "bold")),
locations = cells_body(columns = `Moda (Mo)`)) %>%
opt_table_font(font = google_font("Roboto")) %>%
tab_options(table.font.size = px(13), heading.align = "left", data_row.padding = px(8))| CONCLUSIONES Y ESTADÍSTICOS | ||||||||||
| Resumen de indicadores del tipo de pozo — Nueva York | ||||||||||
| Variable | Rango [Min; Max] | Media (X) | Mediana (Me) | Moda (Mo) | Varianza (S2) | Desv. Est. (S) | C.V. (%) | Asimetria (As) | Curtosis (K) | Valores Atipicos |
|---|---|---|---|---|---|---|---|---|---|---|
| Tipo de pozo | N/A | N/A | N/A | OD | N/A | N/A | N/A | N/A | N/A | N/A |
| Autor: DALLYANA | ||||||||||
La moda corresponde al tipo OD, el más frecuente entre los pozos de Nueva York. Al ser una variable cualitativa nominal, no aplican medidas como la media, la mediana o la desviación estándar; el análisis se basa en las frecuencias absolutas (ni) y relativas (hi) de cada categoría mostradas en la tabla y las gráficas anteriores.