Instruction guide to produce a median rainfall map for January in Ireland using the dplyr package in R

This document provides the neccessary steps to produce a map displaying the median rainfall in January for 25 stations across the island. The data is taken from 165 years of observations, 1850 - 2014. Dr. Simon Noone homogenized data for a precipitation network in Ireland, adding 17 stations to the composite series through work for his PhD. Further information on this work can be found in this paper Homogenization and analysis of an expanded long-term monthly rainfall network for the Island of Ireland (1850-2010) DOI:10.1002/joc.4522.

Preparing R
As this map is produced in R, there are some libraries that need to be loaded along with the appropriate data. The following calls are used to do this:

library(dplyr)
library(leaflet)
library(ggvis) 
library(RColorBrewer)

setwd("D:\\CC\\R\\CB's Lecture Resources") 
#This will be different for everyone's computer, the filing system needs to be consulted to find the correct pathway. 
load('rainfall.RData')

Compiling appropriate data
This assignment asks for the January median rainfall only, the following code will gather only this observational data into a data frame named ‘median_monthly_stations’:

rain %>% group_by(Month, Station) %>%
  filter(Month=='Jan') %>% 
  summarise(medRain=median(Rainfall)) %>%
  arrange(desc(medRain)) -> median_monthly_stations

Joining tables
Currently there is no geographical information tied to this data so it can’t be plotted on a map. This is resolved using a left_join, which joins two tables together allowing for both the median january rainfall data and the geographical information to be stored in ‘station_median’ (dpylr, 2018).

median_monthly_stations %>% left_join(stations) %>% arrange(desc(medRain)) -> station_median

Now all the relevant data is in one place it is possible to plot a map. Some preparatory tasks are required also though.

Preparing the colour scheme
It is important to set up the colour scheme that will operate on the map. ‘BuPu’, used here, is a colour scheme that tracks the lowest values in the lightest blue, through to darker blues and purples as values rise. To see the colour scheme in action, a preview function with a five number summary is called.

color_fun <- colorNumeric('BuPu', station_median$medRain)
previewColors(color_fun, fivenum(station_median$medRain))

This shows the lowest median value (Dublin Airport with 63mm) as an almost white colour, while the highest value (Killarney 177.7mm) as a deep purple. This colour scheme will be used to colour code the circle for each station on the map according to the level of median rainfall for that station in January.

Preparing popups for the map

Popup <- paste0(station_median$Station,'_',station_median$medRain)

The popup code allows for information to ‘pop up’ when a circle is clicked on in the map. The code above will call the station name with the median rainfall, e.g. the median rainfall in Galway University for the entire series in January is 124.1, so when this circle is clicked the following is visible: ‘University College Galway_124.1’. Try it out on the map below.

Coding the map
The code that brings it all together into a working map is:

leaflet(data = station_median, height = 430, width = 600) %>% addProviderTiles('CartoDB.Positron') %>%
  setView(-8,53.5,6) %>% addCircleMarkers(fillColor = ~color_fun(medRain), weight = 0.5, fillOpacity = 0.85, popup=~Popup) %>%
  addLegend(pal=color_fun, values = ~medRain, title = "Median Jan Rainfall", position = "bottomleft")

Figure 1: Median Rainfall map of Ireland in January for 25 stations

Discussion of patterns
Median values represent the middle value when all of the vaules have been sorted in ascending order. Therefore the area with the highest median rainfall will also have the higest maximum rainfall, and the station with the lowest median rainfall will have the lowest minimum rainfall.
There are very clear patterns evident in the January median rainfall (Figure 1). The inland areas are more sheltered from rain resulting in lower values in the midlands from Limerick to Armagh. The figure of the mean annual rainfall map for Ireland, 1981-2010 (Figure 2), provides a visual representation of the general precipiation pattern for the island. Although not matching the parameters focussed here, it does display similar patterns of rainfall, as evident in the map above, and confimed in Table 1. The higher values are associated with places along the coast, and areas of high altitude.

Figure2: Annual Mean Rainfall map of Ireland (mm), 1981-2010

Source: Met Éireann, 2018b

Source: Met Éireann, 2018b

Killarney has the highest median rainfall, not surprising due to its proximity to Ireland’s highest mountain, Carrauntoohil (Figure 3), and to the Atlantic ocean. The Atlantic is the dominant influence of weather in Ireland (Met Éireann, 2018a). While altitude can increase precipitation in the West of Ireland by 200mm for every 100 m rise in altitude (Met Éireann, 2018b).

Figure3: Carrauntoohil, Co. Kerry

Source: Activeme.ie, 2014

Source: Activeme.ie, 2014

Ardara in Donegal, and Valentia in Kerry also have high median rainfall levels for January and are both highlighted in a deep purple. Although Dublin is coastal, and two of the stations with the lowest values for median rainfall in January are based in Dublin, its sheltered location from the Atlantic and corresponding weather patterns afford it drier conditions than a coastal area on the west coast.

Table 1: Median rainfall per station in January thorughout the series 1850-2014
Month Station medRain
Jan Killarney 177.7
Jan Ardara 171.6
Jan Valentia 166.0
Jan Cappoquinn 147.4
Jan Cork Airport 134.6
Jan Rathdrum 126.6
Jan Enniscorthy 126.4
Jan University College Galway 124.1
Jan Portlaw 123.3
Jan Markree Castle 116.0
Jan Roches Point 111.0
Jan Malin Head 106.9
Jan Foulksmills 105.7
Jan Waterford 102.6
Jan Strokestown 102.5
Jan Belfast 102.1
Jan Drumsna 99.1
Jan Derry 97.3
Jan Shannon Airport 92.9
Jan Athboy 87.1
Jan Mullingar 80.6
Jan Birr 77.5
Jan Armagh 75.0
Jan Phoenix Park 67.6
Jan Dublin Airport 63.0

Reference List:

Activeme.ie (2014) Carrauntoohil Mountain [online]. Available at: https://www.activeme.ie/guides/walks/carrauntoohil-mountain-via-devils-ladder-kerry/ (accessed 10 January 2018).

dplyr (2018) Join two tbls together [online]. Available at: http://dplyr.tidyverse.org/reference/join.html (accessed 9 January 2018).

Met Éireann (2018a) Climate of Ireland [online]. Available at: https://www.met.ie/climate-ireland/climate-of-ireland.asp (accessed 9 January 2018).

Met Éireann (2018b) Rainfall [online]. Available at: https://www.met.ie/climate-ireland/rainfall.asp (accessed 9 January 2018).

Noone, S. et al (2016) Homogenization and analysis of an expanded long-term monthly rainfall netword for the Island of Ireland (1850-2010). International Journal of Climatology [online] 36: 2837-2853. Available at: DOI:10.1002/joc.4522 (accessed 13 December 2017).