knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
fmir provides simple tools for easily accessing up to date, open weather data from Finland. The data are made available by the Finnish Meteorological Institute and are licensed under CC-BY 4.0. See FMI's open data manual for details.
Key features in fmir include:
FMI provides varying types of data in several different formats in their API, implemented using OGC Web Feature Service (WFS). Currently the only format supported by fmir is the "simple" weather format. For a more comprehensive and feature-rich package for accessing the FMI API, check out https://github.com/rOpenGov/fmi.
The first step is to install fmir from github with devtools
:
# install.packages("devtools") devtools::install_github("mikmart/fmir")
To start with, load the package:
library(fmir)
We can construct queries to the API with fmi_query()
, and then execute them with fmi_data()
. A simple query with only a place
parameter will return weather observations with a 10-minute interval for the past 12 hours:
# generate a (vector of) query url(s) q <- fmi_query(place = c("Espoo", "Oulu", "Rovaniemi")) # download the data corresponding to the query weather <- fmi_data(q) weather
Having the data at hand, we can then use ggplot2 to draw a simple line graph of the recent temperatures in Espoo, Oulu and Rovaniemi:
library(ggplot2) # draw a simple line graph of the recent temperature ggplot(weather, aes(time, t2m)) + geom_line(aes(colour = place))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.