UNIVERSIDAD CENTRAL DEL ECUADOR

PROYECTO:ESTUDIO ESTADÍSTICO DE LA CALIDAD DEL AIRE EN INDIA

FECHA: 21/11/2025

#Estadística Descriptiva
#Ariana Viteri
#20/11/2025

library(gt)
library(dplyr)

#Cargar los datos 

datos<-read.csv("~/ariana tercer semestre/Estadistica/city_day.csv",header = TRUE,dec = ".",sep = ",")

#Tablas Cualitativas Nominales

#AQI_Bucket 
AQI_Bucket <- datos$AQI_Bucket
#Tabla de distribución de frecuencia
TDF_AQI_Bucket <- data.frame(table(AQI_Bucket ))
ni <- TDF_AQI_Bucket$Freq
hi <- round((ni / sum(ni)) *100,2)
AQI_Bucket <- TDF_AQI_Bucket$AQI_Bucket
TDF_AQI_Bucket <- data.frame(AQI_Bucket,ni,hi)
Summary <- data.frame(AQI_Bucket = "TOTAL", ni=sum(ni), hi = 100)

TDF_AQI_Bucket_suma <- rbind(TDF_AQI_Bucket,Summary)

colnames(TDF_AQI_Bucket_suma) <- c("AQI_Nivel", "ni", "hi(%)")

# TABLA 

TDF_AQI_Bucket_suma %>%
  gt() %>%
  tab_header(
    title = md("Tabla Nro. 5"),
    subtitle = md("Tabla de distribución de frecuencias del nivel de contaminación")
  ) %>%
  tab_source_note(
    source_note = md("Fuente: Datos procesados por el autor a partir de archivo city.day.csv ")
  ) %>%
  tab_style(
    style = cell_borders(
      sides = "left",
      color = "black",
      weight = px(2),
      style = "solid"
    ),
    locations = cells_body()
  ) %>%
  tab_style(
    style = cell_borders(
      sides = "right",
      color = "black",
      weight = px(2),
      style = "solid"
    ),
    locations = cells_body()
  ) %>%
  tab_style(
    style = cell_borders(
      sides = "left",
      color = "black",
      weight = px(2),
      style = "solid"
    ),
    locations = cells_column_labels()
  ) %>%
  tab_style(
    style = cell_borders(
      sides = "right",
      color = "black",
      weight = px(2),
      style = "solid"
    ),
    locations = cells_column_labels()
  )%>%
  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. 5
Tabla de distribución de frecuencias del nivel de contaminación
AQI_Nivel ni hi(%)
- 4681 15.85
Good 1341 4.54
Moderate 8829 29.90
Poor 2781 9.42
Satisfactory 8224 27.85
Severe 1338 4.53
Very Poor 2337 7.91
TOTAL 29531 100.00
Fuente: Datos procesados por el autor a partir de archivo city.day.csv
#Tabla No.1
#Distribuccion de AQI_Nivel

#GDF 1

TDF_AQI_Bucket$Zona <- iconv(TDF_AQI_Bucket$AQI_Bucket, from = "latin1", to = "UTF-8", sub = "")
barplot(
  height = TDF_AQI_Bucket$ni,
  names.arg = TDF_AQI_Bucket$AQI_Bucket,
  main = "Gráfica No. 1.1: Distribución de AQI_Bucket",
  xlab = "",
  ylab = "Cantidad",
  col = heat.colors(length(TDF_AQI_Bucket$ni)),
  las = 2,
  cex.names = 0.7
)
mtext("AQI_Bucket", side = 1, line = 4, cex = 1)

# DIAGRAMA DE BARRAS (GLOBAL)

colores <- c("yellow", "orange", "red")

barplot(TDF_AQI_Bucket$ni,
        main = "Gráfica 1.2: Distribución de AQI_Bucket",
        xlab = "",
        ylab = "Cantidad",
        
        col = colores,
        names.arg = TDF_AQI_Bucket$variable,
        ylim = c(0, 22500),
        las = 2,
        cex.names = 0.7
)
mtext("AQI_Bucket", side = 1, line = 4, cex = 1)

# DIAGRAMA DE BARRAS (Porcentaje)

barplot(TDF_AQI_Bucket$hi,
        main = "Grafica No 1.3: Distribución de Zona (porcentaje) de
AQI_Bucket",
        xlab = "",
        ylab = "Porcentaje (%)",
        col = colores,
        names.arg = TDF_AQI_Bucket$variable,
        ylim = c(0, 30),
        las = 2,
        cex.names = 0.7
)
mtext("AQI_Bucket", side = 1, line = 4, cex = 1)

# DIAGRAMA DE BARRAS (Porcentaje)

colores <- c("yellow", "orange")

"barplot"(TDF_AQI_Bucket$hi,
          main = "Grafica N°1.4: Distribución de AQI_Bucket (Porcentaje)",
          xlab = "",
          ylab = "Porcentaje (%)",
          col = colores,
          names.arg = TDF_AQI_Bucket$variable,
          ylim = c(0, 100),
          las = 2,
          cex.names = 0.7
)
mtext("AQI_Bucket", side = 1, line = 2, cex = 1)

#Diagrama Circular 
library(RColorBrewer)
n <- length(TDF_AQI_Bucket$AQI_Bucke)
colores <- brewer.pal(min(n, 12), "Set3") 
color <- adjustcolor(colores, alpha.f = 0.9)
etiqueta<-paste(hi,"%")

pie(hi,
    labels = etiqueta,
    radius = 1,
    col=color,
    main="Gráfica No.1.5: 
    Porcentaje de AQI_Bucket")

legend(x = 1.3, y = 0.8,
       legend=TDF_AQI_Bucket$AQI_Bucket,
       title = "Leyenda",
       fill=color,
       cex = 0.9)