This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.

#Estadistica Descriptiva

#Grupo 3

#20/11/2025


#Cargar Datos

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

str(datos)
## 'data.frame':    3000 obs. of  24 variables:
##  $ Case_ID                      : chr  "CASE_100000" "CASE_100001" "CASE_100002" "CASE_100003" ...
##  $ Date_Reported                : chr  "12/9/2024" "1/1/2024" "24/2/2025" "24/9/2024" ...
##  $ Region                       : chr  "Africa" "Africa" "Europe" "Asia" ...
##  $ Country                      : chr  "Pakistan" "Germany" "Germany" "USA" ...
##  $ Pollutant_Type               : chr  "Lead" "Lead" "Lead" "Lead" ...
##  $ Pollutant_Concentration_mg_kg: int  7804 1633 16733 8923 9393 12347 644 1171 11161 12159 ...
##  $ Soil_pH                      : int  83 796 535 566 764 518 489 814 524 819 ...
##  $ Temperature_C                : int  356 310 164 314 170 123 339 191 439 131 ...
##  $ Humidity_.                   : int  649 731 338 305 586 912 530 697 781 347 ...
##  $ Rainfall_mm                  : int  624 82 1217 1169 2370 3863 488 1247 3758 181 ...
##  $ Crop_Type                    : chr  "Wheat" "Potato" "Soybean" "Wheat" ...
##  $ Farming_Practice             : chr  "Integrated" "Permaculture" "Organic" "Permaculture" ...
##  $ Nearby_Industry              : chr  "Mining" "Mining" "Chemical" "None" ...
##  $ Water_Source_Type            : chr  "Well" "Irrigation Canal" "River" "Irrigation Canal" ...
##  $ Soil_Texture                 : chr  "Sandy" "Silty" "Clay" "Silty" ...
##  $ Soil_Organic_Matter_.        : int  198 971 549 398 94 818 52 544 90 359 ...
##  $ Disease_Type                 : chr  "Gastrointestinal Disease" "Cancer" "Gastrointestinal Disease" "Neurological Disorder" ...
##  $ Disease_Severity             : chr  "Moderate" "Mild" "Severe" "Severe" ...
##  $ Health_Symptoms              : chr  "Breathing Difficulty" "Breathing Difficulty" "Nausea" "Fatigue" ...
##  $ Age_Group_Affected           : chr  "Adults" "Elderly" "Children" "Adults" ...
##  $ Gender_Most_Affected         : chr  "Male" "Both" "Both" "Male" ...
##  $ Mitigation_Measure           : chr  "Government Regulation" "Community Awareness" "Soil Remediation" "Community Awareness" ...
##  $ Case_Resolved                : chr  "No" "Yes" "Yes" "Yes" ...
##  $ Follow_Up_Required           : chr  "Yes" "No" "No" "No" ...
#Tablas Cualitativas 

#Enfermedad

Enfermedad <- datos$Disease_Type

#Tabla de Distribucion de Frecuencia De los Tipos de Enfermedades

TDF_Enfermedad <-data.frame(table(Enfermedad))

ni <- TDF_Enfermedad$Freq
hi <- round((ni / sum(ni)) * 100, 2)
Enfermedad <- TDF_Enfermedad$Enfermedad

TDF_Enfermedad <- data.frame(Enfermedad, ni, hi)

Summary <- data.frame(Enfermedad = "TOTAL", ni = sum(ni),hi = 100)
TDF_Enfermedad_suma <- rbind(TDF_Enfermedad,Summary)
colnames(TDF_Enfermedad_suma) <- c("Enfermedad", "ni", "hi(%)")

#Graficas
# Diagrama de barrras local ni

barplot(ni, main = "Gráfica N°42: Distribución de frecuencias de las distintas 
        Enfermedades",
        xlab = "Enfermedad",
        ylab = "Cantidad",
        col = "red",
        ylim = c(0,622),
        las = 1,
        cex.names = 0.55,
        names.arg = TDF_Enfermedad$Enfermedad)

#Diagrama de barras global ni 

barplot(ni, main = "Gráfica N°43: Distribución de frecuencias de las distintas 
        Enfermedades",
        xlab = "Enfermedad",
        ylab = "Cantidad",
        col = "skyblue",
        ylim = c(0,3000),
        las=1,
        cex.names = 0.56,
        names.arg = TDF_Enfermedad$Enfermedad)

#Diagrama de barras local hi(%)

barplot(hi, main = "Gráfica N°44: Distribución de frecuencias porcentual de las distintas 
        Enfermedades",
        xlab = "Enfermedad",
        ylab = "Porcentaje",
        col = "green",
        ylim = c(0,21),
        las = 1,
        cex.names = 0.56,
        names.arg = TDF_Enfermedad$Enfermedad)

#Diagrama de barras global hi(%)

barplot(hi, main = "Gráfica N°45: Distribución de frecuencias porcentual de las distintas 
        Enfermedades",
        xlab = "Enfermedad",
        ylab = "Porcentaje",
        col = "blue",
        ylim = c(0,100),
        las = 1,
        cex.names = 0.56,
        names.arg = TDF_Enfermedad$Enfermedad)

#Diagrama circular

etiqueta_pie <- paste(TDF_Enfermedad$hi, "%")
pie(hi,
    main = "Gráfica N°46 Distribución porcentual de las distintas Enfermedades",
    radius = 1,
    labels = etiqueta_pie,
    col = rev(heat.colors(length(hi))),
    cex = 0.8,
    cex.main = 1)

legend("topright",
       legend = TDF_Enfermedad$Enfermedad,
       fill = colores <- c(rev(heat.colors(10))),
       cex = 0.56,
       title = "Leyenda")