1 CARGA DE DATOS Y LIBRERIAS

CARGA DE LIBRERÍAS

library(readxl)
library(dplyr)
## 
## 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
library(stringr)
library(gt)

CARGA DE DATOS

datos <- read_excel("D:/mining_dataset_ajustado.xlsx")

# Verificamos columnas
names(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"
Metodo <- datos$Metodo_Extraccion


df_metodo <- data.frame(variable = Metodo, stringsAsFactors = FALSE)

2 TABLA DE VALORES

# 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

3 GRAFICAS

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))

moda_metodo <- TDF_metodo[TDF_metodo$ni == max(TDF_metodo$ni), ]
moda_metodo
## # A tibble: 1 × 3
##   grupo            ni    hi
##   <chr>         <int> <dbl>
## 1 CIELO ABIERTO  1080    54