library(meteospain)
library(sf)
library(purrr)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
library(units)
# provide keys for aemet and meteocat if not done already
# keyring::key_set('aemet')
# keyring::key_set('meteocat')
meteospain
aims to return stations data in a compatible
format between services. This means:
sf
object.This ease combining data from different services. Let’s see an example.
We are gonna download daily data for April, 2020 for all services providing this information, and combine them in one object:
Don’t forget to store the keys for AEMET and MeteoCat if not done already (see code above)
<- get_meteo_from(
aemet_daily 'aemet', aemet_options(
'daily', start_date = as.Date('2020-04-01'), end_date = as.Date('2020-04-30'),
api_key = keyring::key_get('aemet')
)
)
<- get_meteo_from(
meteocat_daily 'meteocat',
meteocat_options('daily', start_date = as.Date('2020-04-01'), api_key = keyring::key_get('meteocat'))
)
<- get_meteo_from(
meteogalicia_daily 'meteogalicia',
meteogalicia_options('daily', start_date = as.Date('2020-04-01'), end_date = as.Date('2020-04-30'))
)
<- get_meteo_from(
ria_daily 'ria',
ria_options('daily', start_date = as.Date('2020-04-01'), end_date = as.Date('2020-04-30'))
)
Now we have all daily data for April, lets join them. We are gonna
use the purrr package to do it in one pipe.
Here we convert the data to tibble before the join, that way we are not
joining by the spatial data, but by timestamp and the stations metadata.
After the join we convert back to sf
.
<- list(
april_2020_spain ::as_tibble(aemet_daily),
dplyr::as_tibble(meteocat_daily),
dplyr::as_tibble(meteogalicia_daily),
dplyr::as_tibble(ria_daily)
dplyr%>%
) ::reduce(dplyr::full_join) %>%
purrr::st_as_sf()
sf
april_2020_spain
We can visualize the data, only one day.
%>%
april_2020_spain ::filter(lubridate::day(timestamp) == 25) %>%
dplyr::drop_units() %>%
unitsggplot(aes(colour = service)) +
geom_sf() +
scale_colour_viridis_d()
%>%
april_2020_spain ::filter(lubridate::day(timestamp) == 25) %>%
dplyr::drop_units() %>%
unitsggplot(aes(colour = mean_temperature)) +
geom_sf() +
scale_colour_viridis_c()