https://github.com/patrickbarks/cantempr
R package to access long-term homogenized temperature data for 338 Canadian climate stations
https://github.com/patrickbarks/cantempr
climate-data r rstats temperature-data
Last synced: 7 days ago
JSON representation
R package to access long-term homogenized temperature data for 338 Canadian climate stations
- Host: GitHub
- URL: https://github.com/patrickbarks/cantempr
- Owner: patrickbarks
- License: gpl-2.0
- Created: 2019-01-09T19:21:00.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-10T11:47:05.000Z (over 7 years ago)
- Last Synced: 2025-10-26T01:27:59.668Z (9 months ago)
- Topics: climate-data, r, rstats, temperature-data
- Language: R
- Homepage:
- Size: 844 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
---
output: github_document
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
eval = TRUE,
fig.path = "man/img/"
)
options(digits = 4)
```
# cantempr
[](https://travis-ci.org/patrickbarks/cantempr) [](https://ci.appveyor.com/project/patrickbarks/cantempr) [](https://codecov.io/github/patrickbarks/cantempr?branch=master)
An R package to access long-term homogenized temperature data for 338 Canadian climate stations (for some stations data is available as far back as 1841). These data come from [Vincent et al. (2012)](https://doi.org/10.1029/2012JD017859), and are available in station-specific text files from [Environment and Climate Change Canada](https://www.canada.ca/en/environment-climate-change/services/climate-change/science-research-data/climate-trends-variability/adjusted-homogenized-canadian-data/surface-air-temperature-access.html) (see file 'Monthly mean of daily mean temperature').
__Data citation__: Vincent, L. A., X. L. Wang, E. J. Milewska, H. Wan, F. Yang, and V. Swail (2012) A second generation of homogenized Canadian monthly surface air temperature for climate trend analysis. Journal of Geophysical Research 117(D18110). [https://doi.org/10.1029/2012JD017859](https://doi.org/10.1029/2012JD017859)
## Installation
Install from GitHub with:
```{r, eval=FALSE}
# first install package 'remotes' if necessary (a dependency of devtools)
# install.packages("remotes")
remotes::install_github("patrickbarks/cantempr")
```
## Usage
```{r}
library(cantempr)
```
#### Fetch data
Temperature data can be fetched using the `cantemp_fetch()` function. Temperature data is available at monthly, seasonal, and annual intervals (selected with argument `interval`).
```{r}
temp_annual <- cantemp_fetch(interval = "annual") # fetch annual data
```
Let's take a peek.
```{r}
head(temp_annual)
```
We can also fetch station-specific metadata (including lat/lon/elevation, and details on the temporal extent of the temperature data) using the function `cantemp_meta()`.
```{r}
stn_metadata <- cantemp_meta()
```
#### Barcode plot
The `cantempr` package includes a function to produce 'temperature barcode plots' (see examples [here](https://www.cbc.ca/news/technology/charts-climate-change-bar-codes-1.4802293)). Here's an example barcode plot using a time-series of mean annual temperatures in Toronto, Ontario.
```{r, fig.width=8, fig.height=3}
library(ggplot2)
# subset annual temperature data to Toronto
temp_to <- subset(temp_annual, station == "TORONTO")
# create barcode plot
cantemp_barcode(temp_to, x_breaks = seq(1850, 2010, 20)) +
ggtitle(paste("Mean annual temperatures in Toronto since", min(temp_to$year)))
```
#### Seasonal temperature trends
Here's a more traditional plot of long-term temperature trends, by season, in Hay River, Northwest Territories.
```{r, fig.width=8, fig.height=6}
# subset to seasonal temperature data for Hay River, Northwest Territories
temp_seasonal <- cantemp_fetch(interval = "seasonal")
temp_hr <- subset(temp_seasonal, station == "HAY RIVER" & !is.na(temp))
# plot
ggplot(temp_hr, aes(year, temp)) +
geom_line() +
geom_smooth(method = "loess") +
scale_x_continuous(breaks = seq(1900, 2020, 20)) +
scale_y_continuous(labels = function(x) paste0(x, "\u00B0C")) +
facet_wrap(~ interval, ncol = 2, scales = "free_y") +
ggtitle(paste("Mean seasonal temperatures in Hay River, NWT, since", min(temp_hr$year))) +
theme_minimal() + theme(axis.title = element_blank())
```
## Contributions
All contributions are welcome. Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms.