README.md

The rainfall package

The rainfall package automatically downloads and processes rainfall data from the Climatic Research Unit at the University of East Anglia.

Installation

The package is currently only available on GitHub. It can be installed through the devtools package.

devtools::install_github("felixhaass/rainfall")

Functions & Output

The package uses basically only one function: download_rain. This functions takes as input an ISO3 country code and downloads a file with monthly rainfall data for this country.

It outputs a data.frame with the following variables.

For more information see help(download_rain).

If you supply a vector of ISO3 country codes download_rain() will download and combine the data for each country.

Usage

We download monthly rainfall data for the Democratic Republic of the Congo. To get the DRC's ISO3 code we use the excellent countrycode package.

library(countrycode)
library(rainfall)

country_iso3_list <- countrycode("Democratic Repulic of the Congo", 
                                 "country.name",
                                 "iso3c")

drc_rain <- download_rain(country = country_iso3_list, 
                          long = T, delete_raw = T)

This produces the following data.frame named drc_rain (only last 12 rows are shown):

| iso3c | YEAR| month | month_numeric| rain| MAM| JJA| SON| DJF| ANN| |:------|-----:|:------|---------------:|------:|------:|------:|------:|----:|-------:| | COD | 2015| JAN | 1| 123.0| 439.1| 189.7| 476.8| NA| 1503.6| | COD | 2015| FEB | 2| 124.7| 439.1| 189.7| 476.8| NA| 1503.6| | COD | 2015| MAR | 3| 175.5| 439.1| 189.7| 476.8| NA| 1503.6| | COD | 2015| APR | 4| 147.9| 439.1| 189.7| 476.8| NA| 1503.6| | COD | 2015| MAY | 5| 115.8| 439.1| 189.7| 476.8| NA| 1503.6| | COD | 2015| JUN | 6| 56.3| 439.1| 189.7| 476.8| NA| 1503.6| | COD | 2015| JUL | 7| 55.5| 439.1| 189.7| 476.8| NA| 1503.6| | COD | 2015| AUG | 8| 77.9| 439.1| 189.7| 476.8| NA| 1503.6| | COD | 2015| SEP | 9| 128.0| 439.1| 189.7| 476.8| NA| 1503.6| | COD | 2015| OCT | 10| 162.6| 439.1| 189.7| 476.8| NA| 1503.6| | COD | 2015| NOV | 11| 186.2| 439.1| 189.7| 476.8| NA| 1503.6| | COD | 2015| DEC | 12| 150.3| 439.1| 189.7| 476.8| NA| 1503.6|

The same works for multiple countries:

# Note that we add several countries to the list
country_list <- c("Democratic Repulic of the Congo",
                  "Germany", 
                  "Philippines", 
                  "Algeria")

country_iso3_list <- countrycode(country_list, 
                                 "country.name",
                                 "iso3c")

compare_rain <- download_rain(country = country_iso3_list, 
                          long = T, delete_raw = T)

We can now plot comparison of rainfall in these countries in 2015:

library(ggplot2)
library(dplyr)

compare_rain_plot <- compare_rain %>% 
  filter(YEAR == 2015) %>% 
  ggplot(., 
         aes(x = month_numeric, y = rain, group =iso3c)) +
  geom_line(aes(color = iso3c)) +
  scale_color_brewer(palette = "RdYlGn") +
  theme_bw() +
  scale_x_continuous(breaks=1:12, labels = month.abb) +
  labs(x = "", y = "Monthly Average Rainfall")

print(compare_rain_plot)

More information on the data

I did not create this data! For more information on the data, see the original research article describing the data:

Harris, I, PD Jones, TJ Osborn & DH Lister (2014) Updated high-resolution grids of monthly climatic observations - the CRU TS3.10 Dataset. International Journal of Climatology 34(3): 623-642.

Or check out the accompanying web page.

Feedback & Questions

For feedback, questions, and problems regarding the package, please use GitHub Issues..



felixhaass/rainfall documentation built on May 16, 2019, 12:48 p.m.