This blog will describe the processes taken to create a map of the median rainfall in Ireland for 25 weather stations during January, each station will be colour coded according to its median rainfall level in January.
To begin, the working directory was set and the following data and packages were loaded.
load("C:/Users/35385/Desktop/R/rainfall.RData")
library(dplyr)
library(leaflet)
library(viridis)
This provided me with two datasets (“rain” and “stations”), to begin “rain” was viewed.
View(rain)
The data was then sorted by year and month into a new dataset called “rain2.”
rain %>% arrange(Year,Month) -> rain3
The data was then examined, January’s rainfall data was extracted to a new dataset named “January.”
View(rain3)
january_data<-rain%>%
filter((Month== "Jan"))
The following function was used to calculate the median rainfall for each station in January.
median_rainfall<-january_data%>%
group_by(Station)%>%
summarize(median_january_rainfall=median(Rainfall, na.rm = TRUE))
The latitude and longitude data for each station was extracted from another dataset, it was then merged with the rainfall dataset to create “merged_data.”
merged_data<-merge(median_rainfall, stations, by="Station", all.x = TRUE)
The code below generated a map using the “leaflet” function. The code added circle markers to the map of Ireland to represent each of the 25 weather stations.
Features of map:
Colour scheme: Viridis palette.
Popups: Displays rainfall information when clicked.
Labels: Displays labels on the markers.
Group: used to group markers.
Next, a legend was added to the map to explain the colour coding of each marker. The Values were also reversed to show higher levels of rainfall in purple and lower levels in yellow.
View(merged_data)
rainfall_map1<-leaflet(merged_data)%>%
addTiles %>%
addCircleMarkers( ~Long, ~Lat,
color = ~colorBin(palette = "viridis",
bins = 5,
domain = c(min(merged_data$median_january_rainfall), max(merged_data$median_january_rainfall)),
reverse = TRUE)(median_january_rainfall),
radius = 5,
popup = ~paste("Station: ", Station, "<br>Median Rainfall in January: ", median_january_rainfall, " mm"),
label = ~paste(median_january_rainfall, "mm"),
group = "Weather Stations"
) %>%
addLegend(
pal = colorBin(palette = "viridis",
bins = 5,
domain = c(min(merged_data$median_january_rainfall), max(merged_data$median_january_rainfall)),
reverse = TRUE),
values = ~median_january_rainfall,
title = "Median Rainfall in January (mm)",
position = "bottomright"
) %>%
addLayersControl(
overlayGroups = "Weather Stations",
options = layersControlOptions(collapsed = FALSE)
)
rainfall_map1
The final map (seen above), clearly illustrates the median rainfall in January for each of the 25 weather stations. This rainfall data used in this analysis was collected over an extensive period, it ranges from 1850-2014.
On initial inspection it is clear that the higher median levels have been recorded along the west coast of Ireland (Donegal, Mayo, Galway, Kerry and Cork). The highest median level of rainfall was recorded in Killarney, County Kerry at an average of 177.7mm during January.
Areas that experience a lower median rainfall in January are mostly contained within the midlands (Offaly, Westmeath and Meath) The lowest median level of rainfall was recorded in the Phoenix Park, Dublin at an average of 67.6mm during January.
Overall, this map provides a clear geographical distribution of the median rainfall in Ireland for 25 weather stations from 1850-2014. This map provides valuable insights into regional patterns and allows for observations of long term-trends and changes in rainfall patterns. The visualisation and accessibility of the map allows for an easy interpretation of complex data and therefore allows for the effective communication of this data it to a broader audience.