aemet_forecast_tidy {climaemet} | R Documentation |
Helper functions for extracting forecasts
Description
Helpers for aemet_forecast_daily()
and aemet_forecast_hourly()
:
-
aemet_forecast_vars_available()
extracts the values available on the dataset. -
aemet_forecast_tidy()
produces atibble
with the forecast forvar
.
Usage
aemet_forecast_tidy(x, var)
aemet_forecast_vars_available(x)
Arguments
x |
A database extracted with |
var |
Name of the desired var to extract |
Value
A vector of characters (aemet_forecast_vars_available()
)
or a tibble
(aemet_forecast_tidy()
).
See Also
Other forecasts:
aemet_forecast_beaches()
,
aemet_forecast_daily()
Examples
# Hourly values
hourly <- aemet_forecast_hourly(c("15030", "28080"))
# Vars available
aemet_forecast_vars_available(hourly)
# Get temperature
temp <- aemet_forecast_tidy(hourly, "temperatura")
library(dplyr)
# Make hour - Need lubridate to adjust timezones
temp_end <- temp %>%
mutate(
forecast_time = lubridate::force_tz(
as.POSIXct(fecha) + hora,
tz = "Europe/Madrid"
)
)
# Add also sunset and sunrise
suns <- temp_end %>%
select(nombre, fecha, orto, ocaso) %>%
distinct_all() %>%
group_by(nombre) %>%
mutate(
ocaso_end = lubridate::force_tz(
as.POSIXct(fecha) + ocaso,
tz = "Europe/Madrid"
),
orto_end = lubridate::force_tz(
as.POSIXct(fecha) + orto,
tz = "Europe/Madrid"
),
orto_lead = lead(orto_end)
) %>%
tidyr::drop_na()
# Plot
library(ggplot2)
ggplot(temp_end) +
geom_rect(data = suns, aes(
xmin = ocaso_end, xmax = orto_lead,
ymin = min(temp_end$temperatura),
ymax = max(temp_end$temperatura)
), alpha = .4) +
geom_line(aes(forecast_time, temperatura), color = "blue4") +
facet_wrap(~nombre, nrow = 2) +
scale_x_datetime(labels = scales::label_date_short()) +
scale_y_continuous(labels = scales::label_number(suffix = "ยบ")) +
labs(
x = "", y = "",
title = "Forecast: Temperature",
subtitle = paste("Forecast produced on", format(temp_end$elaborado[1],
usetz = TRUE
))
)
[Package climaemet version 1.3.0 Index]