1 CARGA DE DATOS

setwd("~/UNI/ESTADISTICA")
datos <- read.csv("Depositos_Sulfuro.csv", header = TRUE, sep = ";", dec = ".")

Verificamos que nos lea correctamente los datos

TIPO_DEPOSITOS <-datos$deptype
str(TIPO_DEPOSITOS)
##  chr [1:1090] "Mafic" "Felsic" "Felsic" "Felsic" "Mafic" "Bimodal-Mafic" ...

2 TABLA DE DISTRIBUCIÓN DE FRECUENCIA POR TIPO DE DEPOSITOS

# 1. Extraer variable tipo de depósito
Tipo_Deposito <- datos$deptype

# Reemplazar NA por "Sin Registro"
TipoDep_limpio <- ifelse(is.na(Tipo_Deposito) | trimws(Tipo_Deposito) == "",
                         "Sin Registro",
                         trimws(Tipo_Deposito))

TIPODEPOSITO <- factor(TipoDep_limpio)

# 2. Tabla de frecuencia (ni)
TablaTIPODEPOSITO <- as.data.frame(table(TIPODEPOSITO))
colnames(TablaTIPODEPOSITO) <- c("TIPODEPOSITO", "ni")

# 3. Porcentaje hi
TablaTIPODEPOSITO$hi <- round((TablaTIPODEPOSITO$ni / sum(TablaTIPODEPOSITO$ni)) * 100,2)

# 4. Fila TOTAL
Total <- data.frame(
  TIPODEPOSITO = "TOTAL",
  ni = sum(TablaTIPODEPOSITO$ni),
  hi = round(sum(TablaTIPODEPOSITO$hi),)
)

# 5. Tabla final
TablaFinalTD <- rbind(TablaTIPODEPOSITO, Total)

TablaFinalTD
##    TIPODEPOSITO   ni     hi
## 1 Bimodal-Mafic  358  32.84
## 2        Felsic  529  48.53
## 3         Mafic  202  18.53
## 4  Sin Registro    1   0.09
## 5         TOTAL 1090 100.00

#Tabla N° 1 — Distribución por Tipo de depositos masivos de sulfuro volcanicos

tabla_TD_gt <- TablaFinalTD %>%
  gt() %>%
  tab_header(
    title = md("**Tabla N° 1**"),
    subtitle = md("Distribución por tipo de Depósitos <br>
                     Masivos de Sulfuro Volcánicos")
  ) %>%
  tab_source_note(
    source_note = md("Autor: Grupo 2")
  ) %>%
  tab_options(
    table.border.top.color = "black",
    table.border.bottom.color = "black",
    heading.border.bottom.color = "black",
    heading.border.bottom.width = px(2),
    column_labels.border.top.color = "black",
    column_labels.border.bottom.color = "black",
    column_labels.border.bottom.width = px(2),
    table_body.hlines.color = "gray",
    table_body.border.bottom.color = "black",
    row.striping.include_table_body = TRUE
  ) %>%
  tab_style(
    style = cell_text(weight = "bold"),
    locations = cells_body(rows = TIPODEPOSITO == "Total")
  )

tabla_TD_gt
Tabla N° 1
Distribución por tipo de Depósitos
Masivos de Sulfuro Volcánicos
TIPODEPOSITO ni hi
Bimodal-Mafic 358 32.84
Felsic 529 48.53
Mafic 202 18.53
Sin Registro 1 0.09
TOTAL 1090 100.00
Autor: Grupo 2

3 DIAGRAMAS DE BARRAS Y DIAGRAMA CIRCULAR

3.1 Diagrama de barras ni local

barplot(TablaFinalTD$ni[1:(nrow(TablaFinalTD)-1)],
        main = "Gráfica Nº1: Distribución por tipo de Depósito masivos de
        sulfuros volcanicos  (Local)",
        cex.main=0.8,
        xlab = "Tipo de deposito",
        ylab = "Cantidad (ni)",
        names.arg = TablaFinalTD$TIPODEPOSITO[1:(nrow(TablaFinalTD)-1)]
)

3.2 Diagrama de barras ni global

barplot(
  TablaFinalTD$ni[1:(nrow(TablaFinalTD)-1)],
  main = "Gráfica Nº2: Distribución por Tipo de Depósitos masivos de sulfuros volcanicos (Global)",
  cex.main = 0.8,
  xlab = "Tipo de Deposito",
  ylab = "Cantidad (ni)",
  col = "blue",
  names.arg = TablaFinalTD$TIPODEPOSITO[1:(nrow(TablaFinalTD)-1)],
  ylim = c(0, 1090)
)

3.3 Diagrama de barras hi local

hi_local <- as.numeric(TablaFinalTD$hi[1:(nrow(TablaFinalTD)-1)])
barplot(
  hi_local,
  main = "Gráfica Nº3:Distribución por Tipo de Depósitos masivos de sulfuros volcanicos (Local)",
  cex.main = 0.8,
  xlab = "Continente",
  ylab = "Porcentaje (%)",
  col = "blue",
  names.arg = TablaFinalTD$TIPODEPOSITO[1:(nrow(TablaFinalTD)-1)] ,
  cex.names = 1,
  ylim = c(0, 50)
)

3.4 Diagrama de barras hi global

hi_global <- as.numeric(TablaFinalTD$hi[1:(nrow(TablaFinalTD)-1)])
barplot(
  hi_global,
  main = "Gráfica Nº4: Distribución por Tipo de Depósitos masivos de sulfuros volcanicos (Global)",
  cex.main = 0.8,
  xlab = "Continente",
  ylab = "Porcentaje (%)",
  col = "blue",
  names.arg = TablaFinalTD$TIPODEPOSITO[1:(nrow(TablaFinalTD)-1)],
  cex.names = 1,
  ylim = c(0, 100)
)

3.5 Diagrama circular

hi_TD <- as.numeric(TablaFinalTD$hi[1:(nrow(TablaFinalTD)-1)])
TD <- TablaFinalTD$TIPODEPOSITO[1:(nrow(TablaFinalTD)-1)]

Colores <- colorRampPalette(c("lightskyblue", "darkblue"))

etiquetas <- paste0(round(hi_TD), "%")

pie(
  hi_TD,
  radius = 0.8,
  col = Colores(length(hi_TD)),
  labels = etiquetas,
  main = "Gráfica Nº5: Distribución por Tipo de depositos masivos de sulfuros volcanicos",
  cex.main = 0.8
)

# LEYENDA
legend(
  "bottomright",
  title = "Tipo de Depositos",
  legend = TD,
  fill = Colores(length(hi_TD)),
  cex = 0.8
)