climaemet

June 19, 2026 · View on GitHub

rOS-badge CRAN
status CRAN_time_from_release CRAN_latest_release_date CRAN
results r-universe R-CMD-check codecov DOI metacran
downloads GitHub
License Project Status: Active – The project has reached a stable, usable
state and is being actively
developed.

climaemet provides access to meteorological observations, forecasts, alerts and climatology data from the Spanish Meteorological Agency (AEMET). It also includes tools for working with tabular and spatial data and for creating Walter-Lieth climate diagrams, warming stripes and wind roses.

Browse the manual and vignettes at https://ropenspain.github.io/climaemet/.

AEMET API

AEMET OpenData is a REST API for accessing and reusing the agency’s meteorological and climatological information. For details, visit https://opendata.aemet.es/centrodedescargas/inicio.

License for the original data

The data are prepared by the Spanish Meteorological Agency (© AEMET). See the AEMET legal notice for details.

A summary of data usage is:

People can use these data freely. You should mention AEMET as the collector of the original data in every situation except when you are using these data privately and individually. AEMET makes no warranty as to the accuracy or completeness of the data. All data are provided on an “as is” basis. AEMET is not responsible for any damage or loss derived from the interpretation or use of these data.

Installation

Install the released version of climaemet from CRAN with:

install.packages("climaemet")

Install the development version of climaemet from r-universe:

# Install climaemet in R:
install.packages(
  "climaemet",
  repos = c(
    "https://ropenspain.r-universe.dev",
    "https://cloud.r-project.org"
  )
)

Alternatively, install the development version of climaemet with:

# install.packages("pak")
pak::pak("ropenspain/climaemet")

API key

To download data from AEMET, you need a free API key, which you can get here.

library(climaemet)

## Get API key from AEMET.
browseURL("https://opendata.aemet.es/centrodedescargas/altaUsuario")

## Set the API key for the current R session.
aemet_api_key("MY API KEY")

Migrating from versions before 1.0.0

Versions before 1.0.0 accepted an apikey argument in data-access functions. Current code should set the API key globally with aemet_api_key() and remove the obsolete apikey argument.

Tabular results

climaemet returns tabular results as tibble objects. The package also infers column types when possible. For example, date and time columns are parsed as date-time objects and numeric columns are parsed as doubles.

library(climaemet)

# See a tibble in action

aemet_last_obs("9434")
#> ! HTTP `429`:
#>   Límite de peticiones o caudal por minuto excedido para este usuario. Espere
#>   al siguiente minuto.
#> ℹ Retrying.
#> Waiting 4s for retry backoff ■■■■■■■■
#> Waiting 4s for retry backoff ■■■■■■■■■■■■■■■■■■
#> Waiting 4s for retry backoff ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
#>
#> # A tibble: 13 × 25
#>    idema   lon fint                 prec   alt  vmax    vv    dv   lat  dmax
#>    <chr> <dbl> <dttm>              <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#>  1 9434  -1.00 2026-06-18 23:00:00     0   249   9.1   6.1   120  41.7   130
#>  2 9434  -1.00 2026-06-19 00:00:00     0   249   9.5   5.5   120  41.7   133
#>  3 9434  -1.00 2026-06-19 01:00:00     0   249   7.7   4.7   110  41.7   100
#>  4 9434  -1.00 2026-06-19 02:00:00     0   249   7.9   4.2   109  41.7   113
#>  5 9434  -1.00 2026-06-19 03:00:00     0   249   6.6   4     118  41.7   118
#>  6 9434  -1.00 2026-06-19 04:00:00     0   249   5.3   2.3   115  41.7   120
#>  7 9434  -1.00 2026-06-19 05:00:00     0   249   3.2   1.9   118  41.7    85
#>  8 9434  -1.00 2026-06-19 06:00:00     0   249   4.9   1.9   114  41.7   135
#>  9 9434  -1.00 2026-06-19 07:00:00     0   249   7     4.5   134  41.7   130
#> 10 9434  -1.00 2026-06-19 08:00:00     0   249   6.5   4.4   112  41.7   113
#> 11 9434  -1.00 2026-06-19 09:00:00     0   249   8.1   4.5   112  41.7   118
#> 12 9434  -1.00 2026-06-19 10:00:00     0   249   8.2   5.4   122  41.7   125
#> 13 9434  -1.00 2026-06-19 11:00:00     0   249   9.1   5.1   105  41.7    88
#> # ℹ 15 more variables: ubi <chr>, pres <dbl>, hr <dbl>, stdvv <dbl>, ts <dbl>,
#> #   pres_nmar <dbl>, tamin <dbl>, ta <dbl>, tamax <dbl>, tpr <dbl>,
#> #   stddv <dbl>, inso <dbl>, tss5cm <dbl>, pacutp <dbl>, tss20cm <dbl>

Spatial outputs

Data-access functions that support return_sf = TRUE can return spatial sf objects. These objects use the EPSG:4326 coordinate reference system (CRS), corresponding to the World Geodetic System 1984 (WGS 84), with unprojected longitude and latitude coordinates:

# You need to install sf if it is not already installed.
# Run install.packages("sf") to install it.
library(ggplot2)
library(dplyr)

all_stations <- aemet_daily_clim(
  start = "2021-01-08",
  end = "2021-01-08",
  return_sf = TRUE
)

ggplot(all_stations) +
  geom_sf(aes(colour = tmed), shape = 19, size = 2, alpha = 0.95) +
  labs(
    title = "Average temperature in Spain",
    subtitle = "8 Jan 2021",
    color = "Max temp.\n(celsius)",
    caption = "Source: AEMET"
  ) +
  scale_colour_gradientn(
    colours = hcl.colors(10, "RdBu", rev = TRUE),
    breaks = c(-10, -5, 0, 5, 10, 15, 20),
    guide = "legend"
  ) +
  theme_bw() +
  theme(
    panel.border = element_blank(),
    plot.title = element_text(face = "bold"),
    plot.subtitle = element_text(face = "italic")
  )

Example of map created with climaemet and sf.

Plots

You can create warming stripes from weather-station temperature data. The plotting functions return ggplot2 objects:

# Plot warming stripes for a weather station.

library(ggplot2)

# Example data
temp_data <- climaemet::climaemet_9434_temp

ggstripes(temp_data, plot_title = "Zaragoza Airport") +
  labs(subtitle = "(1950-2020)")

Warming stripes created with climaemet.

You can also create a Walter-Lieth climate diagram for a weather station over a specified period:

# Plot a Walter-Lieth climate diagram for a weather station.

# Example data
wl_data <- climaemet::climaemet_9434_climatogram

ggclimat_walter_lieth(
  wl_data,
  alt = "249",
  per = "1981-2010",
  est = "Zaragoza Airport"
)

Walter-Lieth climate diagram for a weather station.

You can also create a wind rose from weather-station wind speed and direction data.

# Plot a wind rose for a weather station.

# Example data
wind_data <- climaemet::climaemet_9434_wind

speed <- wind_data$velmedia
direction <- wind_data$dir

ggwindrose(
  speed = speed,
  direction = direction,
  speed_cuts = seq(0, 16, 4),
  legend_title = "Wind speed (m/s)",
  calm_wind = 0,
  n_col = 1,
  plot_title = "Zaragoza Airport"
) +
  labs(subtitle = "2000-2020", caption = "Source: AEMET")

Wind rose showing wind speed and direction.

Code of conduct

This project is released with a Contributor Code of Conduct. By participating, you agree to abide by its terms.

Citation

If you use climaemet in a paper, please consider citing it:

Pizarro M, Hernangómez D, Fernández-Avilés G (2021). climaemet: Climate AEMET Tools. doi:10.5281/zenodo.5205573.

A BibTeX entry for LaTeX users is:

@Manual{10261_250390,
  author = {Manuel Pizarro and Diego Hernangómez and Gema Fernández-Avilés},
  title = {{climaemet}: Climate {AEMET} Tools},
  year = {2021},
  abstract = {The goal of climaemet is to serve as an interface to download the climatic data of the Spanish Meteorological Agency (AEMET) directly from R using their API (https://opendata.aemet.es/) and create scientific graphs (climate charts, trend analysis of climate time series, temperature and precipitation anomalies maps, “warming stripes” graphics, climatograms, etc.).},
  doi = {10.5281/zenodo.5205573},
}