UNIVERSIDAD CENTRAL DEL ECUADOR

ESTUDIO ESTADÍSTICO DE LA CONTAMINACIÓN DEL SUELO Y SU IMPACTO EN LA SALUD

FECHA: 19/11/2025

#Estadistica Descriptiva

#19/11/2025

library(dplyr)
library(gt)

setwd("/cloud/project")

datos<-read.csv("soil_pollution_diseases.csv",header = TRUE,dec = ".",
                sep = ",")

#Tablas Cualitativas Nominales

#Region

Region<-datos$Region

# Tabla de distribución de frecuencia

TDF_Region<-data.frame(table(Region))

ni <- TDF_Region$Freq
hi <- round((ni / sum(ni)) * 100, 2)
Region <- TDF_Region$Region
TDF_Region <- data.frame(Region, ni, hi)
Summary <- data.frame(Region = "TOTAL", ni = sum(ni),hi = 100)

TDF_Region_suma<-rbind(TDF_Region, Summary)
colnames(TDF_Region_suma) <- c("Región", "ni", "hi(%)")

# TABLA 

TDF_Region_suma %>%
  gt() %>%
  tab_header(
    title = md("*Tabla Nro. 1*"),
    subtitle = md("**Tabla de distribución de las regiones**")
  ) %>%
  tab_source_note(
    source_note = md("Autor: Grupo 3")
  ) %>%
  tab_options(
    table.border.top.color = "black",
    table.border.bottom.color = "black",
    table.border.top.style = "solid",
    table.border.bottom.style = "solid",
    column_labels.border.top.color = "black",
    column_labels.border.bottom.color = "black",
    column_labels.border.bottom.width = px(2),
    row.striping.include_table_body = TRUE,
    heading.border.bottom.color = "black",
    heading.border.bottom.width = px(2),
    table_body.hlines.color = "gray",
    table_body.border.bottom.color = "black"
  )
Tabla Nro. 1
Tabla de distribución de las regiones
Región ni hi(%)
Africa 518 17.27
Asia 528 17.60
Australia 489 16.30
Europe 483 16.10
North America 490 16.33
South America 492 16.40
TOTAL 3000 100.00
Autor: Grupo 3
# Datos para la gráfica

datos<-read.csv("soil_pollution_diseases.csv",header = TRUE,dec = ".",
                sep = ",")
Region <- datos$Region
TDF_Region <- data.frame(table(Region))

ni <- TDF_Region$Freq
hi <- round(ni / sum(ni) * 100, 2)   # porcentajes


#Graficas
# Diagrama de barrras local ni

barplot(ni, main = "Gráfica N°1: Distribución de las regiones",
        xlab = "Regiones",
        ylab = "Cantidad",
        col = "red",
        ylim = c(0,600),
        las = 2,
        cex.names = 0.6,
        names.arg = TDF_Region$Region)

#Diagrama de barras global ni 

barplot(ni, main = "Gráfica N°2: Distribución de las regiones",
        xlab = "Regiones",
        ylab = "Cantidad",
        col = "skyblue",
        ylim = c(0,3000),
        las=2,
        cex.names = 0.6,
        names.arg = TDF_Region$Region)

#Diagrama de barras local hi(%)

barplot(hi, main = "Gráfica N°3: Distribución porcentual de 
        las regiones",
        xlab = "Regiones",
        ylab = "Porcentaje",
        col = "green",
        ylim = c(0,20),
        las = 2,
        cex.names = 0.6,
        names.arg = TDF_Region$Region)

#Diagrama de barras global hi(%)

barplot(hi, main = "Gráfica N°4: Distribución porcentual de 
las regiones",
        xlab = "Regiones",
        ylab = "Porcentaje",
        col = "blue",
        ylim = c(0,100),
        las = 2,
        cex.names = 0.6,
        names.arg = TDF_Region$Region)

#Diagrama circular 

# Etiquetas con número + símbolo %

etiquetas <- paste0(hi, " %")


colores <- c("yellow", "khaki1", "gold", "orange", "darkorange", "red")


par(mar = c(2, 2, 4, 6))

pie(
  hi,
  labels = etiquetas,
  col = colores,
  main = "Gráfica N°5 Distribución porcentual de las regiones",
  cex = 1
)

legend(
  "topright",
  legend = TDF_Region$Region,
  fill = colores,
  title = "Leyenda",
  cex = 0.5,
  xpd = TRUE
)

#Indicadores

# Función de moda
moda <- function(x) {
  frec <- table(x)         
  names(frec)[which.max(frec)]  
}

# Moda de la variable Region
moda(datos$Region)
## [1] "Asia"