Objetivo

Automatizar la generación de reportes climatológicos a partir de datos históricos diarios, con el fin de analizar patrones mensuales de temperatura y precipitación por estación, mediante visualización gráfica.

Contexto Geográfico

Región Puno

Ubicación : Altiplano peruano, frontera con Bolivia.
Altitud: Promedio de 3,827 msnm (una de las regiones más altas del Perú). Variables analizadas : Precipitación, temperatura máxima/mínima (año 2006). Además de la latitud y longitud.
Estaciones : 15 localidades

Obtención de los registros meteorologicos del SENAMHI

La captura de datos fueron obtenidos de la pagina correspondiente a la descarga del SENAMHI.

Figura 1: Región Puno
Figura 1: Región Puno

Descripción del trabajo:

Informacion registrada

“AÑO”, “MES”, “DIA”, “PRECIPITACION”, “TEMP_MAX”, “TEMP_MIN”

Lectura de datos

Librerias usadas

library(dplyr)
library(tidyr)
library(tibble)
library(writexl)

Datos Integrados

# 1. Definir estaciones meteorológicas
estaciones <- c("Puno", "Isla Taquile", "Capachica", "Azangaro", "Arapa",
                "Progreso", "Muñani", "Crucero", "Juli", "Desaguadero",
                "Pizacoma", "Ilave", "Capazo", "Mazo Cruz", "Huancane")

# Vector de meses en español
meses_español <- c("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio",
                   "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre")

# 2. Leer y combinar todos los archivos
datos_completos <- bind_rows(lapply(estaciones, function(est) {
  read.table(paste0(est, ".txt"), header = FALSE,
             col.names = c("AÑO", "MES", "DIA", "PRECIPITACION", "TEMP_MAX", "TEMP_MIN")) %>% 
    mutate(Estacion = est,
           PRECIPITACION = ifelse(PRECIPITACION == -99.9, NA, PRECIPITACION),
           TEMP_MAX = ifelse(TEMP_MAX == -99.9, NA, TEMP_MAX),
           TEMP_MIN = ifelse(TEMP_MIN == -99.9, NA, TEMP_MIN))
}))

año_seleccionado <- 2006

Ejercicios

Generar estadisticas y graficos para cada estacion que escoges

Filtrar los datos para la estación seleccionada

estacion_seleccionada <- "Arapa"

Estadísticas descriptivas

library(tidyr)
library(knitr)
## Warning: package 'knitr' was built under R version 4.4.3
library(kableExtra)
## Warning: package 'kableExtra' was built under R version 4.4.3
## 
## Adjuntando el paquete: 'kableExtra'
## The following object is masked from 'package:dplyr':
## 
##     group_rows
# Filtrar los datos para la estación seleccionada
datos_estacion <- datos_completos %>% 
  filter(Estacion == estacion_seleccionada)

# Calcular las estadísticas descriptivas
estadisticas <- datos_estacion %>%
  summarise(
    # Promedios
    TempMax_Promedio = mean(TEMP_MAX, na.rm = TRUE),
    TempMin_Promedio = mean(TEMP_MIN, na.rm = TRUE),
    Precipitacion_Promedio = mean(PRECIPITACION, na.rm = TRUE),
    
    # Desviaciones estándar
    TempMax_Desviacion = sd(TEMP_MAX, na.rm = TRUE),
    TempMin_Desviacion = sd(TEMP_MIN, na.rm = TRUE),
    Precipitacion_Desviacion = sd(PRECIPITACION, na.rm = TRUE),
    
    # Valores extremos (máximos)
    TempMax_Max = max(TEMP_MAX, na.rm = TRUE),
    TempMin_Max = max(TEMP_MIN, na.rm = TRUE),
    Precipitacion_Max = max(PRECIPITACION, na.rm = TRUE),
    
    # Valores extremos (mínimos)
    TempMax_Min = min(TEMP_MAX, na.rm = TRUE),
    TempMin_Min = min(TEMP_MIN, na.rm = TRUE),
    Precipitacion_Min = min(PRECIPITACION, na.rm = TRUE)
  )

# Reorganizar la tabla a formato vertical
estadisticas_long <- estadisticas %>%
  pivot_longer(
    cols = everything(),
    names_to = "Estadística",
    values_to = "Valor"
  )

# Mostrar la tabla formateada
kable(estadisticas_long, 
      caption = paste("Estadísticas Descriptivas - Estación", estacion_seleccionada)) %>%
  kable_styling(
    bootstrap_options = c("striped", "hover", "condensed", "responsive"),
    full_width = FALSE,
    position = "center"
  )
Estadísticas Descriptivas - Estación Arapa
Estadística Valor
TempMax_Promedio 16.226978
TempMin_Promedio 2.018197
Precipitacion_Promedio 1.885248
TempMax_Desviacion 2.003814
TempMin_Desviacion 3.415649
Precipitacion_Desviacion 4.532843
TempMax_Max 24.400000
TempMin_Max 10.400000
Precipitacion_Max 53.600000
TempMax_Min 2.200000
TempMin_Min -19.400000
Precipitacion_Min 0.000000

Gráfico 1: Temperaturas máximas y mínimas a lo largo del tiempo

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.2
# Crear el gráfico de series temporales de temperaturas
ggplot(datos_estacion, aes(x = as.Date(paste(AÑO, MES, DIA, sep = "-")), group = 1)) +
  geom_line(aes(y = TEMP_MAX, color = "Temp. Máxima"), size = 1) +
  geom_line(aes(y = TEMP_MIN, color = "Temp. Mínima"), size = 1) +
  scale_color_manual(values = c("Temp. Máxima" = "firebrick", "Temp. Mínima" = "steelblue")) +
  labs(
    title = paste("Temperaturas Máxima y Mínima - Estación", estacion_seleccionada),
    subtitle = "Evolución diaria de temperaturas extremas",
    x = "Fecha", 
    y = "Temperatura (°C)", 
    color = "Leyenda:"
  ) +
  theme_minimal(base_size = 12) +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1, size = 10),
    plot.title = element_text(face = "bold", size = 14),
    legend.position = "top",
    panel.grid.major = element_line(color = "gray90"),
    panel.grid.minor = element_blank()
  ) +
  scale_x_date(date_labels = "%b %Y", date_breaks = "3 months")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

Gráfico 2: Precipitación mensual promedio

datos_mes <- datos_estacion %>%
 group_by(MES) %>%
 summarise(Precipitacion_Promedio = mean(PRECIPITACION, na.rm = TRUE)) %>%
 ungroup()
ggplot(datos_mes, aes(x = factor(MES, levels = 1:12, labels = meses_español), y = Precipitacion_Promedio)) +
 geom_bar(stat = "identity", fill = "skyblue") +
 labs(title = paste("Precipitación Promedio Mensual - Estación", estacion_seleccionada),
 x = "Mes", y = "Precipitación Promedio (mm)") +
 theme_minimal()

Gráfico 3: Distribución de temperaturas máximas

ggplot(datos_estacion, aes(x = TEMP_MAX)) +
 geom_histogram(binwidth = 1, fill = "orange", color = "black") +
 labs(title = paste("Distribución de Temperaturas Máximas - Estación", estacion_seleccionada),
 x = "Temperatura Máxima (°C)", y = "Frecuencia") +
 theme_minimal()
## Warning: Removed 316 rows containing non-finite outside the scale range
## (`stat_bin()`).

Gráfico 4: Distribución de temperaturas mínimas

ggplot(datos_estacion, aes(x = TEMP_MIN)) +
 geom_histogram(binwidth = 1, fill = "lightgreen", color = "black") +
 labs(title = paste("Distribución de Temperaturas Mínimas - Estación", estacion_seleccionada),
 x = "Temperatura Mínima (°C)", y = "Frecuencia") +
 theme_minimal()
## Warning: Removed 395 rows containing non-finite outside the scale range
## (`stat_bin()`).

Tablas y graficos (filas=Años, columnas=meses)

Estación elegída

Tabla de máximos por mes y su año

# Filtrar los datos
datos_filtrados <- datos_completos %>%
 filter(Estacion == estacion_seleccionada)
# Crear tabla: filas = años, columnas = meses, valores = Tmax máxima del mes
tabla_temp_max <- datos_filtrados %>%
 group_by(AÑO, MES) %>%
 summarise(TempMax_Mensual = max(TEMP_MAX, na.rm = TRUE)) %>%
 ungroup() %>%
 mutate(MES = factor(MES, levels = 1:12, labels = meses_español, ordered = TRUE)) %>%
 pivot_wider(names_from = MES, values_from = TempMax_Mensual)
## Warning: There were 8 warnings in `summarise()`.
## The first warning was:
## ℹ In argument: `TempMax_Mensual = max(TEMP_MAX, na.rm = TRUE)`.
## ℹ In group 224: `AÑO = 1982` `MES = 7`.
## Caused by warning in `max()`:
## ! ningun argumento finito para max; retornando -Inf
## ℹ Run `dplyr::last_dplyr_warnings()` to see the 7 remaining warnings.
## `summarise()` has grouped output by 'AÑO'. You can override using the `.groups`
## argument.
kable(tabla_temp_max, caption = "Temperatura máxima mensual registrada por año - Estación ") %>%
 kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"),
 full_width = FALSE, position = "center")
Temperatura máxima mensual registrada por año - Estación
AÑO Diciembre Enero Febrero Marzo Abril Mayo Junio Julio Agosto Septiembre Octubre Noviembre
1963 18.4 NA NA NA NA NA NA NA NA NA NA NA
1964 18.6 20.6 19.2 17.2 17.0 16.2 17.0 16.6 18.4 18.6 19.2 18.8
1965 18.4 19.0 17.6 17.0 16.8 18.2 16.2 17.4 18.6 20.0 20.4 20.6
1966 19.6 19.8 18.6 19.2 18.8 17.8 18.0 19.0 18.8 19.8 19.4 19.6
1967 18.2 21.2 18.2 16.8 17.8 18.2 17.6 17.2 17.8 18.4 19.0 19.8
1968 19.0 17.6 16.0 16.6 17.2 17.8 18.0 16.2 19.2 17.6 20.0 18.0
1969 19.8 17.2 18.4 18.6 19.2 19.6 17.4 17.4 17.8 20.4 20.8 21.2
1970 18.4 18.6 18.0 17.4 16.4 18.0 17.4 18.0 19.4 19.6 20.2 20.4
1971 18.2 19.6 15.4 17.4 17.8 17.6 17.6 17.0 19.4 21.0 19.0 18.2
1972 21.0 17.2 17.0 17.4 18.0 17.6 17.2 18.0 19.8 20.0 21.0 20.4
1973 19.2 18.6 18.2 17.2 17.6 17.0 17.0 16.4 19.2 18.8 19.0 21.0
1974 19.2 17.4 16.0 16.4 17.2 16.8 16.8 18.4 17.4 19.2 19.8 21.4
1975 17.8 18.4 16.8 17.8 18.2 16.6 16.4 17.2 19.0 19.0 22.0 19.4
1976 21.4 17.4 19.2 17.6 17.2 18.0 16.4 17.6 19.2 18.8 21.6 20.0
1977 19.6 20.2 19.0 17.4 18.6 17.2 19.4 18.4 19.6 20.2 20.0 19.8
1978 20.4 18.8 18.2 17.8 18.2 19.4 18.2 16.8 19.4 18.8 20.2 18.8
1979 20.0 17.2 19.4 18.4 19.0 19.4 18.4 17.4 17.8 20.8 20.0 20.0
1980 19.4 19.6 19.8 19.0 19.4 19.4 19.4 17.2 19.4 18.6 19.2 21.6
1981 20.4 17.4 17.2 17.8 17.0 17.4 17.8 17.8 18.4 19.4 18.8 20.2
1982 20.0 17.4 19.4 17.6 17.4 17.4 17.4 -Inf 16.6 18.8 18.6 17.8
1983 21.8 20.5 19.4 21.4 19.6 20.6 20.5 20.0 19.6 20.5 19.6 24.0
1984 17.5 19.5 17.9 18.0 19.5 18.6 18.5 18.6 18.8 19.6 18.6 19.5
1985 20.5 16.8 17.4 19.4 20.2 19.5 17.0 20.0 20.6 18.5 21.8 21.5
1986 -Inf 19.0 17.2 16.8 18.5 17.5 18.8 19.8 19.2 18.8 20.0 -Inf
1987 20.0 -Inf 19.5 18.7 19.8 19.5 18.7 18.8 19.0 20.9 19.8 19.4
1988 18.6 17.6 20.4 16.8 16.0 17.2 16.0 17.4 19.0 21.0 21.4 20.4
1989 20.0 17.4 17.0 16.6 17.0 16.8 17.4 16.0 17.0 20.6 19.4 18.8
1990 19.7 18.4 19.0 20.2 19.6 19.8 18.0 17.0 19.6 19.2 21.4 19.2
1991 20.4 19.0 19.8 20.6 18.4 17.0 17.2 17.0 17.8 18.8 19.8 19.8
1992 20.2 16.8 19.0 20.0 20.2 20.4 17.0 17.0 17.8 19.8 20.0 19.4
1993 18.2 16.8 17.4 17.0 17.0 18.0 17.2 18.0 18.6 19.2 19.4 18.8
1994 19.0 18.4 18.8 16.8 17.6 17.4 17.0 17.6 18.8 18.4 19.4 19.6
1995 18.8 18.6 19.2 16.8 17.8 18.6 17.2 19.0 20.4 20.4 21.4 20.4
1996 19.6 19.2 17.2 19.4 18.8 18.0 18.4 17.2 19.4 20.0 19.2 19.6
1997 21.8 18.6 16.4 16.6 17.0 17.2 17.2 17.8 18.0 18.8 20.0 20.2
1998 20.4 20.8 24.4 20.9 21.2 20.0 20.0 19.2 20.2 21.2 21.8 20.4
1999 20.6 20.4 18.8 18.0 18.6 18.6 18.4 19.4 18.0 18.6 18.6 20.4
2000 19.2 18.2 17.4 17.2 18.6 19.4 17.2 17.2 20.2 19.6 19.2 20.6
2001 20.2 16.4 17.6 17.2 17.4 18.6 16.6 16.6 17.2 20.2 21.4 21.0
2002 20.2 19.0 18.2 18.2 18.2 19.2 18.4 17.4 18.6 19.6 19.2 20.0
2003 22.4 19.8 20.0 18.2 19.4 18.2 18.2 18.0 18.8 19.0 21.0 20.2
2004 22.2 18.6 19.0 19.4 19.6 19.2 17.2 19.2 19.4 19.2 21.4 20.4
2005 20.0 20.2 19.0 20.2 19.4 20.2 18.4 18.4 19.6 20.4 20.2 20.6
2006 20.4 18.2 19.6 20.4 19.2 19.2 19.2 18.0 19.2 21.4 20.4 20.2
2007 20.2 21.0 22.2 18.2 18.4 18.6 18.4 18.2 19.2 19.2 21.2 21.2
2008 19.4 17.2 18.4 19.4 19.4 19.4 19.4 18.4 19.0 20.4 20.2 21.4
2009 21.2 19.4 20.4 18.4 19.4 18.4 18.2 19.4 19.2 21.4 21.0 21.4
2010 22.2 20.4 19.6 19.4 20.4 19.6 19.4 20.2 19.4 21.4 21.4 21.6
2011 21.4 21.4 17.4 18.0 19.4 19.4 18.4 18.6 20.0 20.4 20.4 22.0
2012 19.4 17.4 18.0 19.0 18.4 19.0 19.4 19.4 19.0 22.0 22.0 23.0
2013 21.0 -Inf 18.2 18.6 20.0 -Inf -Inf 18.4 19.4 -Inf 22.0 22.4
2014 NA 18.4 19.2 20.2 20.0 19.4 20.4 NA NA NA NA NA

Gráfico de línea con año

# Obtener el valor máximo de cada mes y el año en que ocurrió
max_por_mes <- datos_filtrados %>%
 group_by(MES) %>%
 slice_max(TEMP_MAX, n = 1, with_ties = FALSE) %>%
 ungroup() %>%
 mutate(
 MES = factor(MES, levels = 1:12, labels = meses_español, ordered = TRUE)
 )
ggplot(max_por_mes, aes(x = MES, y = TEMP_MAX)) +
 geom_line(group = 1, color = "darkred", size = 1.2) +
 geom_point(size = 3, color = "firebrick") +
 geom_text(aes(label = AÑO), vjust = -1, size = 4.5, color = "black") +
 labs(title = paste("Temperatura Máxima Histórica por Mes - Estación", estacion_seleccionada),
 subtitle = "Se indica el año en que ocurrió la temperatura más alta de cada mes",
 x = "Mes",
 y = "Temperatura Máxima (°C)") +
 theme_minimal() +
 theme(axis.text.x = element_text(angle = 45, hjust = 1))

Por cada estación

# Función para generar gráfico por estación
grafico_temp_max_por_estacion <- function(estacion) {

 # Filtrar los datos para la estación seleccionada
 datos_filtrados <- datos_completos %>%
 filter(Estacion == estacion) %>%
 group_by(Estacion, AÑO, MES) %>%
 summarise(TempMax_Mensual = max(TEMP_MAX, na.rm = TRUE)) %>%
 ungroup() %>%
 mutate(MES = factor(MES, levels = 1:12, labels = meses_español, ordered = TRUE))

 # Crear el gráfico
 ggplot(datos_filtrados, aes(x = MES, y = TempMax_Mensual, group = AÑO, color = factor(AÑO))) +
 geom_line() +
 labs(title = paste("Temperatura Máxima Mensual - Estación", estacion),
 x = "Mes", y = "Temperatura Máxima (°C)", color = "Año") +
 theme_minimal() +
 theme(axis.text.x = element_text(angle = 45, hjust = 1))
}

Llamar a la función para una estación específica

grafico_temp_max_por_estacion("Puno")
## Warning: There were 2 warnings in `summarise()`.
## The first warning was:
## ℹ In argument: `TempMax_Mensual = max(TEMP_MAX, na.rm = TRUE)`.
## ℹ In group 490: `Estacion = "Puno"`, `AÑO = 2004`, `MES = 11`.
## Caused by warning in `max()`:
## ! ningun argumento finito para max; retornando -Inf
## ℹ Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
## `summarise()` has grouped output by 'Estacion', 'AÑO'. You can override using
## the `.groups` argument.

grafico_temp_max_por_estacion("Huancane")
## Warning: There were 16 warnings in `summarise()`.
## The first warning was:
## ℹ In argument: `TempMax_Mensual = max(TEMP_MAX, na.rm = TRUE)`.
## ℹ In group 5: `Estacion = "Huancane"`, `AÑO = 1964`, `MES = 3`.
## Caused by warning in `max()`:
## ! ningun argumento finito para max; retornando -Inf
## ℹ Run `dplyr::last_dplyr_warnings()` to see the 15 remaining warnings.
## `summarise()` has grouped output by 'Estacion', 'AÑO'. You can override using
## the `.groups` argument.

Tabla y graficos (filas=estaciones, columnas=meses)

Tabla promedio mensual de Temperatura Máxima

```{{r}} promedio_mensual <- datos_completos %>% group_by(Estacion, MES) %>% summarise(Temp_Promedio = mean(TEMP_MAX, na.rm = TRUE)) %>% ungroup() %>% mutate(MES = factor(MES, levels = 1:12, labels = meses_español, ordered = TRUE)) %>% pivot_wider(names_from = MES, values_from = Temp_Promedio) kable(promedio_mensual, caption = “Temperatura máxima promedio mensual por estación”) %>% kable_styling(bootstrap_options = c(“striped”, “hover”, “condensed”, “responsive”), full_width = FALSE, position = “center”)


**Gráfico de temperatura Máxima Promedio Mensual por Estación**


``` r
# Convertir a formato largo para ggplot
datos_largos <- datos_completos %>%
 group_by(Estacion, MES) %>%
 summarise(Temp_Promedio = mean(TEMP_MAX, na.rm = TRUE)) %>%
 ungroup() %>%
 mutate(MES = factor(MES, levels = 1:12, labels = meses_español, ordered = TRUE))
## `summarise()` has grouped output by 'Estacion'. You can override using the
## `.groups` argument.
# Gráfico
ggplot(datos_largos, aes(x = MES, y = Temp_Promedio, group = Estacion, color = Estacion)) +
 geom_line(size = 1) +
 labs(title = "Temperatura Máxima Promedio Mensual por Estación",
 x = "Mes",
 y = "Temp. Máxima Promedio (°C)",
 color = "Estación") +
 theme_minimal() +
 theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Función para generar gráfico de temperatura máxima promedio mensual por estación
grafico_temp_max_promedio_por_estacion <- function(estacion) {

 # Filtrar y calcular la temperatura máxima promedio mensual por estación
 datos_filtrados <- datos_completos %>%
 filter(Estacion == estacion) %>%
 group_by(Estacion, MES) %>%
 summarise(Temp_Promedio = mean(TEMP_MAX, na.rm = TRUE)) %>%
 ungroup() %>%
 mutate(MES = factor(MES, levels = 1:12, labels = meses_español, ordered = TRUE))

 ggplot(datos_filtrados, aes(x = MES, y = Temp_Promedio, group = 1)) +
 geom_line(size = 1, color = "pink") + # Línea de la temperatura promedio
 labs(title = paste("Temperatura Máxima Promedio Mensual - Estación", estacion),
 x = "Mes", y = "Temp. Máxima Promedio (°C)") +
 theme_minimal() +
 theme(axis.text.x = element_text(angle = 45, hjust = 1))
}

Llamar a la función para una estación específica

grafico_temp_max_promedio_por_estacion("Puno")
## `summarise()` has grouped output by 'Estacion'. You can override using the
## `.groups` argument.

grafico_temp_max_promedio_por_estacion("Puno")
## `summarise()` has grouped output by 'Estacion'. You can override using the
## `.groups` argument.

Tabla y grafico para la precipitacion

Tabla Precipitación mensual promedio por estación

precipitacion_mensual <- datos_completos %>%
 group_by(Estacion, AÑO, MES) %>%
 summarise(Precip_Mensual = sum(PRECIPITACION, na.rm = TRUE)) %>%
 ungroup()
## `summarise()` has grouped output by 'Estacion', 'AÑO'. You can override using
## the `.groups` argument.
promedio_mensual_precip <- precipitacion_mensual %>%
 group_by(Estacion, MES) %>%
 summarise(Precip_Promedio = mean(Precip_Mensual, na.rm = TRUE)) %>%
 ungroup() %>%
 mutate(MES = factor(MES, levels = 1:12, labels = meses_español, ordered = TRUE)) %>%
 pivot_wider(names_from = MES, values_from = Precip_Promedio)
## `summarise()` has grouped output by 'Estacion'. You can override using the
## `.groups` argument.
kable(promedio_mensual_precip, caption = "Precipitación mensual promedio por estación (mm)") %>%
 kable_styling(bootstrap_options = c("striped", "hover", "condensed"),
 full_width = FALSE, position = "center")
Precipitación mensual promedio por estación (mm)
Estacion Enero Febrero Marzo Abril Mayo Junio Julio Agosto Septiembre Octubre Noviembre Diciembre
Arapa 132.95098 116.43137 111.61961 44.80980 10.601961 5.770588 3.360000 11.820000 25.068000 49.81800 63.21600 98.57647
Azangaro 99.29275 85.53118 75.75096 32.43462 6.440769 1.683461 1.883529 6.739608 20.331961 38.33412 55.34216 80.16157
Capachica 156.30603 149.07621 129.17271 44.71814 10.335932 3.956034 3.140172 8.863103 23.220345 32.11983 53.07345 108.39966
Capazo 151.50588 132.12941 97.40000 19.93725 4.003922 2.876471 1.830000 4.562200 3.288235 10.13725 26.44314 81.69824
Crucero 151.38912 128.40172 111.43966 52.21034 16.815517 6.617544 4.510526 11.485965 32.285965 52.67544 76.70175 121.02807
Desaguadero 175.32069 149.56155 119.66932 36.97847 8.978814 7.422931 5.259138 12.196897 22.324483 29.84034 53.23310 101.00793
Huancane 140.43654 112.95769 96.44808 40.00769 11.269231 4.584615 3.992308 9.711538 28.778846 47.24808 60.02885 107.26538
Ilave 150.46412 123.62000 98.87843 37.88588 9.815490 5.795200 4.847200 12.729200 21.377400 31.01440 44.42078 80.54843
Isla Taquile 260.13621 225.14190 202.47276 84.92949 28.073390 12.659138 8.069138 16.594828 56.553621 63.08276 81.34655 162.56914
Juli 174.49672 158.94983 138.07153 48.27525 12.101017 5.658983 5.489138 12.770690 27.184138 35.79603 49.79017 112.99552
Mazo Cruz 136.78096 113.00442 81.47827 23.73673 5.366154 1.984808 2.013846 8.033077 7.521923 16.89404 31.41481 77.80327
Muñani 140.03333 109.96667 91.58542 44.03125 7.093750 3.579167 2.772917 7.052083 22.485417 43.72292 59.88750 104.27083
Pizacoma 141.16490 116.75431 81.81196 22.98745 4.964510 3.927255 3.022000 9.224600 7.606800 14.23920 28.34040 101.04078
Progreso 124.34706 101.57255 96.39216 37.73725 6.884314 1.378431 2.872000 5.768000 20.740000 42.50600 59.84600 93.79000
Puno 161.34792 146.02857 135.78571 50.94898 8.938776 3.857143 2.473469 10.561224 25.465306 44.79592 48.67143 90.18571

Grafico linea mensual de precipitacion promedio por estación

datos_grafico <- promedio_mensual_precip %>%
 pivot_longer(cols = -Estacion, names_to = "Mes", values_to = "Precip_Promedio")
# Gráfico
ggplot(datos_grafico, aes(x = Mes, y = Precip_Promedio, group = Estacion, color = Estacion)) +
 geom_line(size = 1) +
 geom_point() +
 labs(title = "Promedio mensual de precipitación por estación",
 x = "Mes",
 y = "Precipitación promedio (mm)") +
 theme_minimal() +
 theme(axis.text.x = element_text(angle = 45, hjust = 1))

#Preparamos los datos
datos_grafico <- promedio_mensual_precip %>%
 pivot_longer(cols = -Estacion, names_to = "Mes", values_to = "Precip_Promedio")
# Ordenar los meses
datos_grafico$Mes <- factor(datos_grafico$Mes, levels = meses_español, ordered = TRUE)
ggplot(datos_grafico, aes(x = Mes, y = Precip_Promedio, group = Estacion)) +
 geom_line(color = "steelblue", size = 1) +
 geom_point(color = "darkblue") +
 facet_wrap(~ Estacion, scales = "free_y") +
 labs(title = "Precipitación mensual promedio (por estación)",
 x = "Mes",
 y = "Precipitación promedio (mm)") +
 theme_minimal(base_size = 12) +
 theme(axis.text.x = element_text(angle = 45, hjust = 1),
 strip.text = element_text(face = "bold"))

Cambiar aquí el nombre de la estación deseada

estacion_deseada <- "Ilave"
precipitacion_mensual <- datos_completos %>%
 group_by(Estacion, AÑO, MES) %>%
 summarise(Precip_Mensual = sum(PRECIPITACION, na.rm = TRUE)) %>%
 ungroup()
## `summarise()` has grouped output by 'Estacion', 'AÑO'. You can override using
## the `.groups` argument.
promedio_mensual_precip <- precipitacion_mensual %>%
 group_by(Estacion, MES) %>%
 summarise(Precip_Promedio = mean(Precip_Mensual, na.rm = TRUE)) %>%
 ungroup() %>%
 mutate(MES = factor(MES, levels = 1:12, labels = meses_español, ordered = TRUE))
## `summarise()` has grouped output by 'Estacion'. You can override using the
## `.groups` argument.
#filtrar solo la estación deseada
datos_estacion <- promedio_mensual_precip %>%
 filter(Estacion == estacion_deseada)
ggplot(datos_estacion, aes(x = MES, y = Precip_Promedio, group = 1)) +
 geom_line(color = "steelblue", size = 1) +
 geom_point(color = "darkblue", size = 2) +
 labs(title = paste("Precipitación mensual promedio - Estación", estacion_deseada),
 x = "Mes",
 y = "Precipitación promedio (mm)") +
 theme_minimal(base_size = 13) +
 theme(axis.text.x = element_text(angle = 45, hjust = 1),
 plot.title = element_text(face = "bold", hjust = 0.5))