Ireland’s Median Rainfall in January 1850-2014

Author

Saoirse Fordham

Published

January 7, 2025

Overview

This blog describes the median rainfall in January from 1850 to 2014 across the 25 weather stations in Ireland. It demonstrates how to create an interactive map of this data in R. Before doing so an explanation of the data sets that are being used is provided. Finally, there is a brief discussion of the spatial patterns that have been identified in the January median rainfall across Ireland.

The data

The data used in this blog is from a rainfall data set supplied by Prof. Conor Murphy and Dr.Simon Noone of ICARUS, which has been converted to an R binary data file for convenience. It contains two objects ‘rain’ and ‘stations’, as displayed below. The rain object contains rainfall data that runs from 1850 to 2014 by month for 25 rainfall stations across the country and has no missing data. The stations object contains information on each of the 25 rainfall stations such as elevation, coordinates and data source.

# A tibble: 49,500 × 4
    Year Month Rainfall Station
 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 
 7  1856 Jan      152.  Ardara 
 8  1857 Jan      179.  Ardara 
 9  1858 Jan      110.  Ardara 
10  1859 Jan      158.  Ardara ...
# ℹ 49,490 more rows
# A tibble: 25 × 9
Station  Elevation Easting Northing   Lat  Long County  Abbreviation Source
  
1 Athboy      87   270400  261700     53.6 -6.93  Meath       AB     Met E…
2 Foulksmills 71   284100  118400     52.3 -6.77  Wexford     F      Met E
3 Mullingar   112  241780  247765     53.5 -7.37  Westme…     M      Met E…
4 Portlaw     8    246600  115200     52.3 -7.31  Waterf…     P      Met E…
5 Rathdrum    131  319700  186000     52.9 -6.22  Wicklow     RD     Met E…
6 Strokestown 49   194500  279100     53.8 -8.1   Roscom…     S      Met E…
7 University..14   129000  225600     53.3 -9.06  Galway      UCG    Met E…
8 Drumsna     45   200000  295800     53.9 -8     Leitrim     DAL    Met E…
9 Ardara      15   180788. 394679.    54.8 -8.29  Donegal     AR     Briffa
10 Armagh     62   287831. 345772.    54.4 -6.64  Armagh      A      Armag…
# ℹ 15 more rows

Mapping January median rainfall

The following sections describe step by step how to create an interactive map showing the median rainfall in January 1850-2014 at each of the 25 rainfall stations across Ireland. The median rainfall values for January are calculated and a map object is created. These rainfall values are plotted for each station and saved as images to use as popups in the map. Finally the popups are added to the map and markers are colour coded corresponding to the magnitude of median rainfall at each location.

Calculating January median values

The code below describes importing the data and loading the necessary packages. The data is then grouped by month and station and the median values are calculated for each month. The median January values are extracted. A filename for each station is created for use later when creating plots.

#Import the data
load('rainfall.RData')
#load required packages
suppressPackageStartupMessages({library(dplyr)
library(tidyr)
library(leaflet)
library(mapview)
library(leafpop)
library(sf) 
library(tmap)
library(ggplot2) })
Warning: package 'dplyr' was built under R version 4.3.1
Warning: package 'mapview' was built under R version 4.3.1
Warning: package 'sf' was built under R version 4.3.1
Warning: package 'ggplot2' was built under R version 4.3.1
#Group data by month and station and calculate median values
rain %>% group_by(Month, Station) %>% 
  summarise(mdrain=median(Rainfall))  ->
  rain_month_station
`summarise()` has grouped output by 'Month'. You can override using the
`.groups` argument.
#rearrange to wide format for clarity
rain_month_station %>% 
  pivot_wider(values_from='mdrain',names_from='Month') -> rain_wide
# A tibble: 25 × 13
Station Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov   Dec
  
1 Ardara 172.  128.  114.   95.9  93.7 104.  122.  144.  143.  169   177.  186. 
2 Armagh 75    51.4  56.3  52.4  54.3  57.1  68.3  82.1  67.6  79.7  71.4  75.3
3 Athboy 87.1  55.9  63.4  56.8  57.8  61.9  72.4  84.5  71.3  84.4  76.6  82.5
4 Belfast 102.   70.4  69.8  62.5  63.5  67.4  82    99.1  84.5 104.   95.8 101... 
#extract January values
rain_wide%>%
  select(Station, Jan) -> january_median

#Make a filename for each station
stations %>% mutate(Filename=file.path(getwd(),paste0(Station,'.png'))) -> files
files %>% select(Station,Filename) 
# A tibble: 25 × 2
   Station                   Filename                                           
   <chr>                     <chr>                                              
 1 Athboy                    /Users/chrisbrunsdon/Downloads/Athboy.png          
 2 Foulksmills               /Users/chrisbrunsdon/Downloads/Foulksmills.png     
 3 Mullingar                 /Users/chrisbrunsdon/Downloads/Mullingar.png       
 4 Portlaw                   /Users/chrisbrunsdon/Downloads/Portlaw.png         
 5 Rathdrum                  /Users/chrisbrunsdon/Downloads/Rathdrum.png        
 6 Strokestown               /Users/chrisbrunsdon/Downloads/Strokestown.png     
 7 University College Galway /Users/chrisbrunsdon/Downloads/University College …
 8 Drumsna                   /Users/chrisbrunsdon/Downloads/Drumsna.png         
 9 Ardara                    /Users/chrisbrunsdon/Downloads/Ardara.png          
10 Armagh                    /Users/chrisbrunsdon/Downloads/Armagh.png          
# ℹ 15 more rows

Creating the map object

The ‘counties.geojson’ file contains geographic data for each county in Ireland, e.g. Names and boundaries. The tmap package can be used to start off the map object as it is easy to use. The leaflet package is used later as it is more powerful and flexible.

#Creating the map object
st_read('counties.geojson',quiet=TRUE) %>% 
  st_transform(4326) -> counties #Changing coordinate refernce system as leaflet objects require data to be in EPSG 4326.
tmap_mode('view')
tmap mode set to interactive viewing
tm_start <- tm_shape(counties) + tm_borders() #Adding county data and boundaries
tm_start

The county data is added as polygon layers to the map to make them interactive, so popups can be added to the map. The county boundary colours are set to none so the polygon outlines are not emphasized. Popups are added as embedded image files (PNG).

tmap_leaflet(tm_start) %>% #Converting tmap to leaflet map
  addPolygons(data=counties,
              color = NA,  
              popup = popupImage('test.png',
                                 embed = TRUE)) 

Creating a plot for each station

The code below involves a loop, where a plot of January median rainfall is created for each station in the files data set that was previously created. Each plot is saved as a PNG image and it is checked the files save correctly.

#Making a plot for each station
for (i in 1:nrow(files)) {
#Open the PNG device
png(files$Filename[i], width = 400, height = 300)
  
#Filter data for the current station
station_data <- january_median[january_median$Station == files$Station[i], ]
  
#Create a ggplot object for the current station
p <- ggplot(station_data, aes(x = Station, y = Jan)) +
    geom_bar(stat = "identity", fill = "skyblue") +  
    theme_minimal() +
    labs(title = paste("Median January Rainfall for", files$Station[i]),
         x = "Station",
         y = "Median Rainfall (mm)") +
    theme(axis.text.x = element_text(angle = 45, hjust = 1))
  
#Print the plot to the PNG device
print(p)
  
#Close the PNG device
dev.off()
}

#Make sure the plots saved correctly
all(file.exists(files$Filename))
[1] TRUE
browseURL(files$Filename[1])

Adding popups to the map object

A file is created containing the station filenames and HTML for embedding the image as a popup. Then the rainfall data and popup information are joined to create a data set ‘station_jan_median’ that contains station coordinates, median rainfall values and the plot files paths to use in the map. An interactive map is created by using this data set and the base map and adding interactive markers. Finally, using the leaflet package the stations are represented using colour coded markers that correspond to the magnitude of median rainfall in January.

#Add popups for January median rainfall plots
files %>%
  mutate(Popup = paste0('<img src="', Filename, '">')) -> files_with_popup
files_with_popup %>% select(Station,Popup)
# A tibble: 25 × 2
   Station                   Popup                                              
   <chr>                     <chr>                                              
 1 Athboy                    "<img src=\"/Users/chrisbrunsdon/Downloads/Athboy.…
 2 Foulksmills               "<img src=\"/Users/chrisbrunsdon/Downloads/Foulksm…
 3 Mullingar                 "<img src=\"/Users/chrisbrunsdon/Downloads/Mulling…
 4 Portlaw                   "<img src=\"/Users/chrisbrunsdon/Downloads/Portlaw…
 5 Rathdrum                  "<img src=\"/Users/chrisbrunsdon/Downloads/Rathdru…
 6 Strokestown               "<img src=\"/Users/chrisbrunsdon/Downloads/Strokes…
 7 University College Galway "<img src=\"/Users/chrisbrunsdon/Downloads/Univers…
 8 Drumsna                   "<img src=\"/Users/chrisbrunsdon/Downloads/Drumsna…
 9 Ardara                    "<img src=\"/Users/chrisbrunsdon/Downloads/Ardara.…
10 Armagh                    "<img src=\"/Users/chrisbrunsdon/Downloads/Armagh.…
# ℹ 15 more rows
#Join January median rainfall data with popup information
january_median %>%
  left_join(files, by = "Station") %>%
  select(Station, Long, Lat, Jan, Filename) %>%
  st_as_sf(coords = c('Long', 'Lat'), crs = 4326) -> station_jan_median


#create map with popups
tmap_leaflet(tm_start) %>% 
  addCircleMarkers(data=station_jan_median, #interactive markers
                   popup=popupImage(
                     station_jan_median$Filename,
                     embed=TRUE))
#create map with colour coded symbols and popups
tm_start2 <- tm_shape(station_jan_median) + 
  tm_dots(col='Jan',popup.vars=FALSE,scale=1.5, palette = "Blues", #Set colour and size of markers
          title = "Median January Rainfall (mm)" ) #Add legend title
tmap_leaflet(tm_start2) %>% 
  addCircleMarkers(data=station_jan_median,
                   stroke = NA,
                   popup=popupImage(
                     station_jan_median$Filename,
                     embed=TRUE)) 

Spatial patterns

The map created displays the median rainfall in January from 1850 to 2014 across the 25 weather stations in Ireland. The map shows that there is higher rainfall along the coast of the island, with less rainfall in the midlands. Interestingly, a report by Met Eireann (https://www.met.ie/climate-ireland/SummaryClimAvgs.pdf ) states that January rainfall for the years 1981-2010, was highest in the western half of the island and lowest in the east. This is consistent with the map created here, as the three stations with highest rainfall, Ardara, Kilarney, and Valentia are in the western half of the island. Although, there is a lack of stations in the western half of the country in this map that would help further validate this, particularly in Galway and Mayo counties. Some locations along the east coast also show lower levels of rainfall.

Concluding remarks

This blog outlines how to create an interactive map of Ireland displaying median January rainfall at 25 rainfall stations from 1850-2014. The map captures the spatial patterns in the January rainfall data, with higher rainfall in the western half of the island compared to the eastern half. As well as this, there is higher rainfall along the coasts compared to the midlands.