NCG602 Climate Change Assignment
Making a map of rainfall for Ireland for the twenty five weather stations, colour coding the symbol for each station according to its median rainfall in level in January.
Using the rainfall data: To use the data these two libraries must be selected.
library(leaflet)
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
##
## Attaching package: 'dplyr'
library(reshape2) # acast
The dataset that will be shown is the rainfall dataset that will be used.It contains the twenty five stations across Ireland.The dataset was downloaded from the NCG602A Moodle page.
Typing in the following commands shows the data.
head(stations)
# A tibble: 6 x 9
Station Elevation Easting Northing Lat Long
<chr> <int> <dbl> <dbl> <dbl> <dbl>
1 Athboy 87 270400 261700 53.6 -6.93
2 Foulks~ 71 284100 118400 52.3 -6.77
3 Mullin~ 112 241780 247765 53.5 -7.37
4 Portlaw 8 246600 115200 52.3 -7.31
5 Rathdr~ 131 319700 186000 52.9 -6.22
6 Stroke~ 49 194500 279100 53.8 -8.1
# ... with 3 more variables: County <chr>,
# Abbreviation <chr>, Source <chr>
dim(stations)
## [1] 25 9
By choosing the “head” command the start year, month, rainfall data and station can be observed.
# head(rain)
# A tibble: 6 x 4
# Year Month Rainfall Station
# <dbl> <fct> <dbl> <chr>
# 1850 Jan 169 Ardara
# 1851 Jan 236. Ardara
# 1852 Jan 250. Ardara
# 1853 Jan 209. Ardara
# 1854 Jan 188. Ardara
# 1855 Jan 32.3 Ardara
# tail(rain)
# A tibble: 6 x 4
# Year Month Rainfall Station
# <dbl> <fct> <dbl> <chr>
# 2009 Dec 99.9 Waterford
# 2010 Dec 70.2 Waterford
# 2011 Dec 80.7 Waterford
# 2012 Dec 114. Waterford
# 2013 Dec 136. Waterford
# 2014 Dec 28.7 Waterford
From observing the data it can be observed that there is no missing values in the dataset. For the purpose of this assignment, it is median of the rainfall values within the month of January. After initally observing the data, the dat is now able to be freely explored.
Exploring the data: Getting the median monthly rainfall.
To get the median monthly rainfall data the following r code was inputted.
#rain_summary <- rain %>% group_by(Month,Station) %>% summarise(mrain=median(Rainfall))
#> head(rain_summary)
# A tibble: 6 x 3
# Groups: Month [1]
# Month Station mrain
# <fct> <chr> <dbl>
# Jan Ardara 172.
# Jan Armagh 75
# Jan Athboy 87.1
# Jan Belfast 102.
# Jan Birr 77.5
# Jan Cappoquinn 147.
The preivous command has given the median rainfall of the stations.
To create a heatmap to visually observe the data to see the median precipation of each station, the following commands were inputted. The data must first be displayed in 2-D to create the heatmap.
#rain_summary %>% acast(Station~Month) %>% head
# Using mrain as value column: use value.var to override.
# Jan Feb Mar Apr May #Jun Jul
#Ardara 171.6 127.5 114.5 95.9 93.7 104.1 121.8
#Armagh 75.0 51.4 56.3 52.4 54.3 57.1 68.3
#Athboy 87.1 55.9 63.4 56.8 57.8 61.9 72.4
#Belfast 102.1 70.4 69.8 62.5 63.5 67.4 82.0
#Birr 77.5 53.3 58.4 49.2 57.3 56.1 72.1
#Cappoquinn 147.4 107.1 110.0 89.4 90.5 83.9 97.0
# Aug Sep Oct Nov Dec
#Ardara 143.7 143.3 169.0 176.9 186.2
#Armagh 82.1 67.6 79.7 71.4 75.3
#Athboy 84.5 71.3 84.4 76.6 82.5
#Belfast 99.1 84.5 104.2 95.8 100.6
#Birr 83.6 68.2 82.0 74.8 78.0
#Cappoquinn 119.3 108.9 141.6 131.9 148.8
Now that the data is displayed in 2-D the following command was used to create the heat map.
Heatmap:
#rain_summary %>% acast(Station~Month) %>% heatmap(Colv=NA)
``` The heat map displays the seasonal patterns in the dataset. This gives a rough idea of what to expect for the median values for January. Areas along the coast of Ireland, such as Rathdrum, Killarney and cork airpor have a higher median of rainfall within the month of januar. This will be confirmed by mapping the data.
The following shows only the January data.
# median_Jan <- rain %>% group_by(Station, Month) %>% filter(Month=='Jan') %>% summarise(mrain=median(Rainfall))> head(median_Jan)
# A tibble: 6 x 3
# Groups: Station [6]
# Station Month mrain
# <chr> <fct> <dbl>
# Ardara Jan 172.
# Armagh Jan 75
# Athboy Jan 87.1
# Belfast Jan 102.
# Birr Jan 77.5
# Cappoquinn Jan 147.
The command just inputted have now sorted and fitlered the station data which results in only the median values for January are chosen.
To map the median rainfall values for January the data needs to be linked to the geographical information using the following function.
# Jan_rain <- median_Jan %>% left_join(stations)
# Joining, by = "Station"
# head(Jan_rain)
# A tibble: 6 x 11
# Groups: Station [6]
# Station Month mrain Elevation Easting #Northing
# <chr> <fct> <dbl> <int> <dbl> # <dbl>
# Ardara Jan 172. 15 180788. #394679.
# Armagh Jan 75 62 287831. 345772.
# Athboy Jan 87.1 87 270400 261700
# Belfast Jan 102. 115 329623. 363141.
# Birr Jan 77.5 73 208017. 203400.
# Cappoq~ Jan 147. 76 213269. 104800.
# ... with 5 more variables: Lat <dbl>, Long <dbl>,
# County <chr>, Abbreviation <chr>, Source <chr>
This line of code was used to colour code the stations for the map. In this case the colour palete ‘Reds’ was chosen.
#color_rain <- colorNumeric('Reds',Jan_rain$mrain)
# previewColors(color_rain,fivenum(Jan_rain$mrain))
63 92.9 105.7 126.4 177.7
the legend contains’fivenum(Jan_rain$mrain)is now compiled into five sections, lighter red colours having the lower value and the higher value having a more intense colour.
Using the leaflet function the interactive map was created.
#leaflet(data=Jan_rain,height=430,width=6#00) %>% addProviderTiles('Stamen.TonerLi#te') %>%
# setView(-8,53.5,6) %>% #addCircleMarkers(fillColor=~color_rain(m#rain),weight=0,fillOpacity = 0.85) %>%
# addLegend(pal=color_rain,values=~mrain#,title="Jan #Rainfall",position='topleft')
(Due to an error the maps cannont be visualised via RMarkdown but can be accessed via r or Rstudio) The leaflet function allows the user to pick the dataset and the over all size of the map.Stamen.TonerLite was chosen as the marker colour scheme is contrasted well. The Latidue and the longitude is displayed via SetView. The stations are marked via the addcirclemarkers using the ‘Reds’ colour scheme to convey the stations to the median rainfall value. Using the addLegend command, the legend is set to the top left of the screen.
Throughout the expirment it is noticed that the stations with the highest median rainfall for January are those stations nearest to the coast.
This due to Irelands prevailing winds as well as its South-Westerly airflows which holds more moisture.
This explains the why the south and west coast espically have the highest median rainfall data. As the south-westerly winds deposit the excess moisutre in these areas.The south-westerly airflows hold far more moisture in contrast to the north-easterly rainflows due to the south-westerly airflows having to travel through the north alantic ocean which gathers far more moisture. This excess moisture rarely ever reaches the midlands and expalins the lower median rainfall in the midlands as well as the north and east coasts.
Using both the heatmap and the rainfall map using the leaflet function, it can be summariesd that it is due to the south-westerly winds collecting more moisture within the Alantic Ocean. Hence why the stations on the west and east coast have a higher median rainfall within the month of January.