Análisis exploratorio de incendios en California (2013-2025)

Carga de bibliotecas

Código
library(tidyverse)
library(lubridate)
library(plotly)

Carga de datos

Código
incendios <- read_csv("incendios-ca-historicos-2013-2025.csv")

incendios_anio <-
  incendios |>
  mutate(
    anio = year(ALARM_DATE)
  ) |>
  group_by(anio) |>
  summarise(
    n                       = n(),                          # cantidad de incendios
    area_quemada_total      = sum(GIS_ACRES, na.rm = TRUE), # área quemada total
    temperatura_2m_promedio = mean(TEMPERATURE_2M_ALARM_DATE, na.rm = TRUE), # temperatura promedio
    .groups                 = "drop"
  )

incendios_mes <-
  incendios |>
  mutate(
    anio = year(ALARM_DATE),
    mes  = month(ALARM_DATE, label = TRUE, abbr = TRUE)
  ) |>
  group_by(anio, mes) |>
  summarise(
    n                       = n(),                          # cantidad de incendios
    area_quemada_total      = sum(GIS_ACRES, na.rm = TRUE), # área quemada total
    temperatura_2m_promedio = mean(TEMPERATURE_2M_ALARM_DATE, na.rm = TRUE), # temperatura promedio
    .groups                 = "drop"
  )

# Asegurar que los meses queden en orden enero-diciembre
incendios_mes$mes <- factor(
  incendios_mes$mes,
  levels = month(ymd("2025-01-01") + months(0:11), label = TRUE, abbr = TRUE)
)

Análisis por año

Cantidad de incendios

Código
# Gráfico de barras agrupadas
g <-
  ggplot(incendios_anio, aes(x = anio, y = n)) +
  geom_col(fill  = "red") +
  labs(
    x     = "Año",
    y     = "Cantidad de incendios"
  ) +
  theme_minimal(base_size = 12) +
  theme(
    panel.grid.major.x = element_blank(),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

# Convertir a interactivo
g_interactivo <- ggplotly(g, tooltip = c("anio", "n"))

# Mostrar
g_interactivo

Área quemada

Código
# Gráfico de barras agrupadas
g <-
  ggplot(incendios_anio, aes(x = anio, y = area_quemada_total)) +
  geom_col(fill  = "red") +
  labs(
    x     = "Año",
    y     = "Área quemada (acres)"
  ) +
  scale_y_continuous(labels = scales::comma) +
  theme_minimal(base_size = 12) +
  theme(
    panel.grid.major.x = element_blank(),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

# Convertir a interactivo
g_interactivo <- ggplotly(g, tooltip = c("anio", "n"))

# Mostrar
g_interactivo

Temperatura promedio del centroide al darse la alarma del incendio

Código
# Gráfico de barras agrupadas
g <-
  ggplot(incendios_anio, aes(x = anio, y = temperatura_2m_promedio)) +
  geom_col(fill  = "red") +
  labs(
    x     = "Año",
    y     = "Temperatura promedio (C)"
  ) +
  scale_y_continuous() +
  theme_minimal(base_size = 12) +
  theme(
    panel.grid.major.x = element_blank(),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

# Convertir a interactivo
g_interactivo <- ggplotly(g, tooltip = c("anio", "temperatura_2m_promedio"))

# Mostrar
g_interactivo

Análisis por mes y año

Cantidad de incendios

Código
# Gráfico de barras agrupadas
g <-
  ggplot(incendios_mes, aes(x = mes, y = n, fill = factor(anio))) +
  geom_col(position = position_dodge(width = 0.8)) +
  labs(
    x     = "Mes",
    y     = "Cantidad de incendios",
    fill  = "Año"
  ) +
  scale_y_continuous(expand = expansion(mult = c(0, 0.05))) +
  scale_fill_brewer(palette = "YlOrRd") +
  theme_minimal(base_size = 12) +
  theme(
    panel.grid.major.x = element_blank(),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

# Convertir a interactivo
g_interactivo <- ggplotly(g, tooltip = c("anio", "mes", "n"))
Warning in RColorBrewer::brewer.pal(n, pal): n too large, allowed maximum for palette YlOrRd is 9
Returning the palette you asked for with that many colors
Código
# Mostrar
g_interactivo

Área quemada

Código
# Gráfico de barras agrupadas
g <-
  ggplot(incendios_mes, aes(x = mes, y = area_quemada_total, fill = factor(anio))) +
  geom_col(position = position_dodge(width = 0.8)) +
  labs(
    x     = "Mes",
    y     = "Área quemada (acres)",
    fill  = "Año"
  ) +
  scale_y_continuous(labels = scales::comma) +
  scale_fill_brewer(palette = "YlOrRd") +
  theme_minimal(base_size = 12) +
  theme(
    panel.grid.major.x = element_blank(),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

# Convertir a interactivo
g_interactivo <- ggplotly(g, tooltip = c("anio", "mes", "area_quemada_total"))
Warning in RColorBrewer::brewer.pal(n, pal): n too large, allowed maximum for palette YlOrRd is 9
Returning the palette you asked for with that many colors
Código
# Mostrar
g_interactivo

Temperatura promedio del centroide al darse la alarma del incendio

Código
# Gráfico de barras agrupadas
g <-
  ggplot(incendios_mes, aes(x = mes, y = temperatura_2m_promedio, fill = factor(anio))) +
  geom_col(position = position_dodge(width = 0.8)) +
  labs(
    x     = "Mes",
    y     = "Temperatura promedio (C)",
    fill  = "Año"
  ) +
  scale_y_continuous() +
  scale_fill_brewer(palette = "YlOrRd") +
  theme_minimal(base_size = 12) +
  theme(
    panel.grid.major.x = element_blank(),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

# Convertir a interactivo
g_interactivo <- ggplotly(g, tooltip = c("anio", "mes", "temperatura_2m_promedio"))
Warning in RColorBrewer::brewer.pal(n, pal): n too large, allowed maximum for palette YlOrRd is 9
Returning the palette you asked for with that many colors
Código
# Mostrar
g_interactivo