FECHA: 23/11/2025
#Estadistica Descriptiva
#Juan Arteaga
#1/12/2025
#VARIABLE CUALITATIVA ORDINAL:
#Cargar los Datos
setwd("C:/Users/arian/OneDrive/Escritorio/3 SEMESTRE/ESTADISTICA Y PROBABILIDAD")
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" ...
#Nivel_Enfermedad
Nivel_Enfermedad<-datos$Disease_Severity
# Tabla de distribución de frecuencia
TDF_Nivel_Enfermedad<-data.frame(table(Nivel_Enfermedad))
ni <- TDF_Nivel_Enfermedad$Freq
hi <- round((ni / sum(ni)) * 100, 2)
Nivel_Enfermedad <- TDF_Nivel_Enfermedad$Nivel_Enfermedad
TDF_Nivel_Enfermedad <- data.frame(Nivel_Enfermedad, ni, hi)
Summary <- data.frame(Nivel_Enfermedad = "TOTAL", ni = sum(ni),hi = 100)
TDF_Enfermedad_suma<-rbind(TDF_Nivel_Enfermedad, Summary)
colnames(TDF_Enfermedad_suma) <- c("Nivel Enfermedad", "ni", "hi(%)")
# Ordenar la tabla en el orden deseado
TDF_Enfermedad_suma$`Nivel Enfermedad` <- factor(
TDF_Enfermedad_suma$`Nivel Enfermedad`,
levels = c("Severe", "Moderate", "Mild", "TOTAL")
)
TDF_Enfermedad_suma <- TDF_Enfermedad_suma[
order(TDF_Enfermedad_suma$`Nivel Enfermedad`),
]
# TABLA
library(gt)
library(dplyr)
TDF_Enfermedad_suma%>%
gt() %>%
tab_header(
title = md("*Tabla Nro. 1*"),
subtitle = md("**Tabla de distribución de frecuencias de los niveles de enfermedad**")
) %>%
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 frecuencias de los niveles de enfermedad |
| Nivel Enfermedad |
ni |
hi(%) |
| Severe |
1023 |
34.10 |
| Moderate |
998 |
33.27 |
| Mild |
979 |
32.63 |
| TOTAL |
3000 |
100.00 |
| Autor: Grupo 3 |
#Graficas
# Diagrama de barrras local ni
barplot(ni, main = "Gráfica N°1: Distribución de frecuencias
de los Niveles de Enfermedad",
xlab = "Niveles de enfermedad",
ylab = "Cantidad",
col = "red",
ylim = c(0,1000),
las = 2,
cex.names = 0.6,
names.arg = TDF_Nivel_Enfermedad$Nivel_Enfermedad)

#Diagrama de barras global ni
barplot(ni, main = "Gráfica N°2: Distribución de frecuencias
de los niveles de enfermedad",
xlab = "Niveles de Enfermedad",
ylab = "Cantidad",
col = "skyblue",
ylim = c(0,3000),
las=2,
cex.names = 0.6,
names.arg = TDF_Nivel_Enfermedad$Nivel_Enfermedad)

#Diagrama de barras local hi(%)
barplot(hi, main = "Gráfica N°3: Distribución de frecuencias porcentual
de los niveles de enfermedad",
xlab = "Niveles de Enfermedad",
ylab = "Porcentaje",
col = "green",
ylim = c(0,40),
las = 2,
cex.names = 0.6,
names.arg = TDF_Nivel_Enfermedad$Nivel_Enfermedad)

#Diagrama de barras global hi(%)
barplot(hi, main = "Gráfica N°4: Distribución de frecuencias porcentual
de los niveles de enfermedad",
xlab = "Niveles de Enfermedad",
ylab = "Porcentaje",
col = "blue",
ylim = c(0,100),
las = 2,
cex.names = 0.6,
names.arg = TDF_Nivel_Enfermedad$Nivel_Enfermedad)

#Diagrama circular
etiqueta_pie <- paste(TDF_Nivel_Enfermedad$hi, "%")
pie(hi,
main = "Gráfica N°5 Distribución porcentual de los niveles de enfermedad",
radius = 1,
labels = etiqueta_pie,
col = rev(heat.colors(length(hi))),
cex = 0.9,
cex.main = 1)
legend("topright",
legend = TDF_Nivel_Enfermedad$Nivel_Enfermedad,
fill = colores <- c(rev(heat.colors(11))),
cex = 0.9,
title = "Leyenda")
