UNIVERSIDAD CENTRAL DEL ECUADOR

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

FECHA: 22/11/2025

#Estadistica Descriptiva
#DANIELA LLUMITASIG
#19/11/2025

library(gt)
library(dplyr)

#Cargar los datos 

datos<-read.csv("C:/Users/JOSELYN/Desktop/kangle/Datos Cambiados.csv",header = TRUE,dec = ".",sep = ",")

#Tablas Cualitativas Nominales

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

TDF_State_suma <- rbind(TDF_State,Summary)

colnames(TDF_State_suma) <- c("Nombre_Oficial", "ni", "hi(%)")

# TABLA 

TDF_State_suma %>%
  gt() %>%
  tab_header(
    title = md("Tabla Nro. 2"),
    subtitle = md("Tabla de distribución de frecuencias de estados de la estación de monitoreo")
  ) %>%
  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. 2
Tabla de distribución de frecuencias de estados de la estación de monitoreo
Nombre_Oficial ni hi(%)
Andhra Pradesh 2413 8.17
Assam 502 1.70
Bihar 1858 6.29
Chandigarh 304 1.03
Delhi 2009 6.80
Gujarat 2009 6.80
Haryana 1679 5.69
Jharkhand 1169 3.96
Karnataka 2009 6.80
Kerala 1436 4.86
Madhya Pradesh 289 0.98
Maharashtra 2009 6.80
Meghalaya 310 1.05
Mizoram 113 0.38
Odisha 1863 6.31
Punjab 1221 4.13
Rajasthan 1114 3.77
Tamil Nadu 2395 8.11
Telangana 2006 6.79
Uttar Pradesh 2009 6.80
West Bengal 814 2.76
TOTAL 29531 100.00
Fuente: Datos procesados por el autor a partir de archivo city.day.csv
#Tabla No.1
#Distribuccion de Estados

#GDF 1

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

# DIAGRAMA DE BARRAS (GLOBAL)

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

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

# DIAGRAMA DE BARRAS (Porcentaje)

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

# DIAGRAMA DE BARRAS (Porcentaje)

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

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

#Diagrama Circular 
library(RColorBrewer)
n <- length(TDF_State$State)
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 estados")

legend("bottomright",legend=TDF_State$State, 
       title = "Leyenda",
       fill=color)