The programming language R is a powerful statistical type of programming language where various statistical techniques are implemented and can be extended through packages. Being a statistical programming language, it is also an effective tool in data analysis as R’s base graphics system gives flexible control over virtually all aspects of a graph or plot (Peng, 2015). This report outlines all relevant steps required in order to produce a web map displaying the median rainfall for the month of January for 25 stations, distributed throughout the whole of Ireland, from which the data is taken for the years 1850 – 2014 (165 years of historical climatology). This report is, arguably, an important piece of work as it allows for an understanding of variations within Ireland’s climate (i.e. extreme rainfall events or droughts) over a long time series. There is also much work done by researchers in gathering information on Ireland’s precipitation. At present, a homogenized Island of Ireland Precipitation (IIP) network comprising of 25 stations and a composite series covering the period 1850–2010 has been constructed (Noone et al, 2016). Long term precipitation time series are useful in understanding past hydrological extremes. For this report there will be, firstly, an exploration of the rainfall data using plots to visualise trends and, most importantly, a map of rainfall in Ireland for 25 weather stations will be constructed by colour coding the symbol representing each station according to its median rainfall level in January (1850-2014). R markdown and R studio will be used to keep this work reproducible so ‘that a third party can replicate’ these results (Brundson, 2016, 687).
The first task was to upload all relevant libraries.
The most important libraries used in this report are:
Library ‘dplyr’ was loaded because it was needed to modify and filter some of the functions used which in turn is important in allowing for the production of the median rainfall map of the 25 weather stations for the month of January.
Library ‘knitr’ was used to allow the document to be published in Rpubs in a HTML blog along with all relevant R code used.
Library ‘leaflet’ was used in the creation of the interactive map of the 25 stations (by median rainfall).
Library ‘RColorBrewer’ was loaded in order to allow for colour palettes to be used to design the map.
The first task was to upload these relevant libraries. The following libraries were used:
library("dplyr")
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library("knitr")
library("leaflet")
library("RColorBrewer")
The colours to be used in the graphs were put into a list. This established the colour scheme and allowed it to be conveniently changed later, if necessary. This was done by using the following code:
graph.colours= c('lightskyblue','lightskyblue1','lightskyblue2','lightskyblue4')
After all libraries were loaded, the working directory needed to be set to access the rainfall data. The rainfall data was then uploaded.
setwd('F:\\Ncg602 rainfall assignment')
load('rainfall.RData')
The rainfall data has two tables (rain and stations). Firstly, rainfall records were examined using the head function(). It can be seen below that the rainfall records contain recorded rainfall values on a daily basis. Rainfall records were examined using the code:
head(rain)
## # A tibble: 6 x 4
## Year Month Rainfall Station
## <dbl> <fct> <dbl> <chr>
## 1 1850 Jan 169 Ardara
## 2 1851 Jan 236. Ardara
## 3 1852 Jan 250. Ardara
## 4 1853 Jan 209. Ardara
## 5 1854 Jan 188. Ardara
## 6 1855 Jan 32.3 Ardara
Secondly, to understand the data further, the stations’ table was explored; the head function () was also used to investigate the stations’ data. Below, it can also be observed that there is good information on the station about the coordinate locations/elevation and notably the location of where each county is situated. Station records were examined by using the code:
head(stations)
## # A tibble: 6 x 9
## Station Elevation Easting Northing Lat Long County Abbreviation Source
## <chr> <int> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr>
## 1 Athboy 87 270400 261700 53.6 -6.93 Meath AB Met Eir~
## 2 Foulksmi~ 71 284100 118400 52.3 -6.77 Wexford F Met Eir~
## 3 Mullingar 112 241780 247765 53.5 -7.37 Westme~ M Met Eir~
## 4 Portlaw 8 246600 115200 52.3 -7.31 Waterf~ P Met Eir~
## 5 Rathdrum 131 319700 186000 52.9 -6.22 Wicklow RD Met Eir~
## 6 Strokest~ 49 194500 279100 53.8 -8.1 Roscom~ S Met Eir~
Before the colour map of the median rainfall of each of the 25 stations across Ireland was made, some visualisations of the data were made in order to understand it. Using the following the Hist() function with the following code (median) included, the distribution of all the stations’ rainfall was investigated:
med.rain = median(rain$Rainfall)
hist(rain$Rainfall, main="Distribution of Rainfall (1850-2014)", col = graph.colours[2], xlab = "Rainfall (mm)")
abline(v=c(med.rain),col=c("blue"),lty=c(2),lwd=c(2))
The data in the above histogram is all data stations combined rainfall values. What is apparent from this, is that all the data is skewed to the right (positively skewed).
To examine the intensity of the median rainfall in January in comparison to other months a bar plot was created using the bar plot function with the code:
rain %>% group_by(Month) %>%
summarise(mrain=median(Rainfall)) -> medrain.monthly
barplot(medrain.monthly$mrain,names=medrain.monthly$Month,las=3,main= 'Median Monthly Rain (1850-2014)', col = graph.colours[1])
It can be observed from the bar-plot created above that December and January, followed by October, have the highest median values of all months of the year. April, May and June have the lowest median rainfall. This graph allows one to observe that the month of January is one of the months of the year with the highest median rainfall.
Using the following code below, a timeseries graph was created to visually examine the median rainfall (January 1850-2014) data:
rain %>% group_by(Year,Month) %>%
summarise(mrain=median(Rainfall)) %>% filter(Month=='Jan') -> jan.rain
plot(jan.rain$mrain[1:165],type='b',ann=F, axes=F, cex=0.6, col = graph.colours[4])
axis(1,at=seq(1,165,by=10),labels=seq(1850,2014, by=10), axis(2), title('Median Rainfall (mm) January 1850-2014'))
From visualising the medians for all of the months of January from 1850-2014, it is hard to pick out any substantial long term trends. There is high variability in rainfall between years, and little correlation year on year. Having a dry January one year is no predictor of a dry January the following year. The wettest January appears to have occurred around 1950, at close to 200mm in the month.
Having explored this data visually through the use of bar-plots, charts and time series graphs for the relevant time periods the next steps will outline how the final map is created along with a discussion on the observed patterns.
Here the data is filtered and combined into a single dataframe called “jan.rain.station”. The dataframe is sorted by station and contains the median rainfall for January as well as coordinates for the station’s location.
rain %>% group_by(Station) %>% filter(Month=="Jan") %>% summarise(mrain=median(Rainfall))-> jan.rain.station.a
jan.rain.station.a %>% left_join(stations) -> jan.rain.station
## Joining, by = "Station"
head(jan.rain.station)
## # A tibble: 6 x 10
## Station mrain Elevation Easting Northing Lat Long County Abbreviation
## <chr> <dbl> <int> <dbl> <dbl> <dbl> <dbl> <chr> <chr>
## 1 Ardara 172. 15 180788. 394679. 54.8 -8.29 Doneg~ AR
## 2 Armagh 75 62 287831. 345772. 54.4 -6.64 Armagh A
## 3 Athboy 87.1 87 270400 261700 53.6 -6.93 Meath AB
## 4 Belfast 102. 115 329623. 363141. 54.5 -5.99 Antrim BF
## 5 Birr 77.5 73 208017. 203400. 53.1 -7.88 Offaly B
## 6 Cappoq~ 147. 76 213269. 104800. 52.2 -7.8 Water~ C
## # ... with 1 more variable: Source <chr>
The display.brewer.pal () function was used to view the colour palette. The “Blues” palette seems most appropriate here to represent rainfall data. The rainfall values corresponding to each colour can be seen below. From using the relevant library, RColorBrewer library, and then the display.brewer.pal () function, a palette seen below was created which represents five different classes, going from almost grey/white (off white) to a dark blue. This seemed most useful as an appropriate colour scheme where the very light colour would represent stations of low median rainfall and areas of dark blue would represent stations with a high median rainfall.
color_fun <- colorNumeric('Blues', jan.rain.station$mrain)
previewColors(color_fun, fivenum(jan.rain.station$mrain))
color_fun
fivenum(jan.rain.station$mrain)
| 63 | |
| 92.9 | |
| 105.7 | |
| 126.4 | |
| 177.7 |
display.brewer.pal(5,"Blues")
A “pop up” was added to the map for added interactivity. When a user clicks on a given rain station, a pop up will appear informing them of the name of the station and the median rainfall. In order to create a pop for the final map the following code was used:
Popup <- paste0('The medain rainfall in January for the ',jan.rain.station$Station,' station was ',jan.rain.station$mrain, ' (mm).')
Having created a suitable colour scheme and a pop up, a map which indicates the median rainfall for each station (by the colour shading of the circular markers which identify stations’ locations and median rainfall by colour intensity) can now be created using the following code:
leaflet(data = jan.rain.station, height = 430, width = 600) %>% addProviderTiles('CartoDB.Positron') %>%
setView(-8,53.5,6) %>% addCircleMarkers(fillColor = ~color_fun(mrain), weight = 0.5, fillOpacity = 0.85, popup=~Popup) %>%
addLegend(pal=color_fun, values = ~mrain, title = "Median Rainfall in January", position = "bottomleft")
## Assuming "Long" and "Lat" are longitude and latitude, respectively
Map of the 25 Weather stations colour coded by median rainfall
For clarity, darker blue colours represent the stations with the highest median rainfall and lighter colours represent all stations with a lower median rainfall
There are some very noticeable patterns evident in the January median rainfall (middle value when all values have been arranged in ascending order) in the colour coded map produced for the 25 weather stations (coded with a colour for the median rainfall). Areas which are inland generally have lower median rainfall values associated with their stations. This is because they are more sheltered than coastal areas whose stations have a greater median rainfall. It can be seen in the map, created of the 25 weather stations by median rainfall, that Killarney has the highest rainfall of 177.7mm, Ardara in Donegal (171.6mm) followed by Valentia in Kerry (166mm) are also stations with the second and third highest median rainfall. In the case of Killarney, it is not surprising that this station has the greatest rainfall, being, as it is, located at the foot of Ireland’s highest mountain and located close to the Atlantic Ocean as the Atlantic plays a key role in influencing Ireland’s climate (Met Eireann, 2020). It is also a fact that these stations in the West of Ireland are located in mountainous areas which contribute to a higher median rainfall. O’Sullivan et al, (2018, 125) points out that in such mountainous areas the ‘annual rainfall increases about 200mm per 100m rise in elevation’ resulting in up to 17% more rain days than in low lying areas.
Dublin had the two weather stations with the lowest median rainfall of all stations despite being located in a coastal area. There are a number of reasons for this, mainly due to it being protected from the Atlantic and its wind patterns, influencing drier conditions. Sweeny (2014) points out that the reason behind the east of Ireland receiving lower rainfall is due to an ‘interaction between relief and Atlantic airstreams’ resulting in rainshadow effects which cause the east of Ireland to have a lower rainfall.
In order to validate these results, as a final step, a bar plot was created to visually show the differences between the median rainfall across the 25 weather stations for the month of January from 1850 to 2014, using the following code:
barplot(jan.rain.station$mrain,names=jan.rain.station$Station, las=3, cex.names = 0.7, ylim=c(0,200), col=graph.colours[3], ylab = "Rainfall (mm)", main = "Median rainfall in January (1850-2014) for Irish weather stations")
This contains the exact same information as the map above showing the median rainfall across Ireland for the 25 weather stations. It can be seen here, as already observed from the map, that Killarney, Ardara and Valentia (weather stations) have the highest median rainfall. Dublin and the midlands have a lower median rainfall.
In conclusion, this report has successfully produced a web map which shows the median rainfall and the variations between stations in rainfall at each of the 25 stations across Ireland. The use of R and markdown has allowed this document to be created in such a way that it can be replicated/reproduced (having outlined and shown each of the steps). Being able to represent climate data and model it in R in a reproducible way helps researchers understand trends in the climate and allows other researchers to use these results for further investigations.
Brunsdon, C. (2016) Quantitative methods I: Reproducible research and quantitative geography. Progress in Human Geography (online) 40 (5). pp. 687-696. Available at: http://mural.maynoothuniversity.ie/9885/1/CB-Quantitative-2016.pdf (Accessed 1 January 2020)
Met Éireann (2020) Climate of Ireland — Rainfall (online). Available at: https://www.met.ie/climate/what-we-measure/rainfall (Accessed 1 January 2020).
Noone, S., Murphy, C., Coll, J., Matthews, T., Mullan, D., Wilby, R. L., and Walsh, S. (2016). Homogenization and analysis of an expanded long-term monthly rainfall network for the Island of Ireland (1850–2010). International Journal of Climatology, 36(8), 2837–2853. Available at: https://doi.org/10.1002/joc.4522 (Accessed 1 January 2020)
O’Sullivan, L., Reidy, B. and Creamer, R. (2018) Mountain Landscapes In: Creamer, R. and O’Sullivan, L. eds. (2018) The Soils of Ireland. World Soils Book Series. Switzerland: Springer International Publishing. Ch. 6.
Peng, R. D. (2015) R Programming for Data Science (e-book). Lean Publishing. Available at: https://www.cs.upc.edu/~robert/teaching/estadistica/rprogramming.pdf (Accessed 1 January 2020)
Sweeney, J. (2014) Regional weather and climates of the British Isles — Part 6: Ireland. Weather, (Online) 69(1), 20—27. Available at: https://doi.org/10.1002/wea.2230 (Accessed 1 January 2020)