CARGA DE LIBRERÍAS
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
CARGA DE DATOS
## [1] "Tipo_Roca" "Zona" "Metodo_Extraccion"
## [4] "Empresa" "Calidad_Mineral" "Fragmentacion"
## [7] "Riesgo_Operativo" "Fallas" "Turno"
## [10] "Equipos_Activos" "Ley_%" "Profundidad_m"
## [13] "Recuperacion_%" "Costo_USD_ton" "Humedad_%"
## [16] "Latitud" "Longitud"
# Agrupación
df_metodo$grupo <- case_when(
str_detect(df_metodo$variable, regex("cielo", ignore_case = TRUE)) ~ "CIELO ABIERTO",
str_detect(df_metodo$variable, regex("subterr", ignore_case = TRUE)) ~ "SUBTERRANEO",
str_detect(df_metodo$variable, regex("mixto", ignore_case = TRUE)) ~ "MIXTO",
TRUE ~ "OTROS"
)
# Frecuencias
TDF_metodo <- df_metodo %>%
group_by(grupo) %>%
summarise(ni = n(), .groups = "drop") %>%
mutate(hi = round((ni / sum(ni)) * 100, 0))
# Total
TDF_metodo_completo <- rbind(
TDF_metodo,
data.frame(
grupo = "TOTAL",
ni = sum(TDF_metodo$ni),
hi = 100
)
)
TDF_metodo_completo## # A tibble: 5 × 3
## grupo ni hi
## <chr> <int> <dbl>
## 1 CIELO ABIERTO 1080 54
## 2 MIXTO 100 5
## 3 OTROS 100 5
## 4 SUBTERRANEO 720 36
## 5 TOTAL 2000 100
tabla_metodo <- TDF_metodo_completo %>%
gt() %>%
tab_header(
title = "Tabla N° 1",
subtitle = "Distribución de Métodos de Extracción"
) %>%
tab_source_note(
source_note = "Autor: Grupo1"
) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_body(rows = grupo == "TOTAL")
)
tabla_metodo| Tabla N° 1 | ||
| Distribución de Métodos de Extracción | ||
| grupo | ni | hi |
|---|---|---|
| CIELO ABIERTO | 1080 | 54 |
| MIXTO | 100 | 5 |
| OTROS | 100 | 5 |
| SUBTERRANEO | 720 | 36 |
| TOTAL | 2000 | 100 |
| Autor: Grupo1 | ||
par(mar = c(8, 4, 4, 2)) # más espacio abajo
barplot(TDF_metodo$ni,
main = "Gráfica Nº1: Frecuencia de Métodos de Extracción",
xlab = "Método",
ylab = "Cantidad (ni)",
col = "steelblue",
names.arg = TDF_metodo$grupo,
las = 1,
cex.names = 0.8) par(mar = c(8, 4, 4, 2)) # más espacio abajo
barplot(TDF_metodo$hi,
main = "Gráfica Nº2: Porcentaje de Métodos de Extracción",
xlab = "Método",
ylab = "Porcentaje (%)",
col = "steelblue",
names.arg = TDF_metodo$grupo,
las = 1,
cex.names = 0.8) # Márgenes para espacio lateral
par(mar = c(4, 4, 4, 8))
# Colores
colores <- rainbow(length(TDF_metodo$hi))
# Gráfico circular
pie(TDF_metodo$hi,
col = colores,
main = "Gráfica Nº3: Distribución porcentual de Métodos de Extracción",
labels = NA)
# Leyenda en cuadro con título
legend("right",
legend = paste(TDF_metodo$grupo, TDF_metodo$hi, "%"),
fill = colores,
title = "GRUPOS",
cex = 0.9,
bty = "o",
xpd = TRUE,
inset = c(-0.15, 0))## # A tibble: 1 × 3
## grupo ni hi
## <chr> <int> <dbl>
## 1 CIELO ABIERTO 1080 54