Introduction
This assignment is based on creating a plotly and ggplot interactive graphs for four weather stations which are Belfast, Dublin Airport, University College Galway, and Cork Airport, and publishing on Rpubs. In this blog, time series graphs showing rainfall on a monthly basis which concurrently changes the time window in all four-time series will be shown. An analysis and discussion of all four-time series will also be provided.
Plotly is R package for creating interactive web-based graphs via plotly’s JavaScript graphing library, plotly.js. The plotly R libary contains the ggplotly function , which will convert ggplot2 figures into a Plotly object. Furthermore, you have the option of manipulating the Plotly object with the style function.
This assignment was created using RStudio programming software, using tools of Rstudio such as RMarkdown to create the blog. The steps performed to create the blog, librarys installed, codes used and source of data will be revealed The aim of this assignment is to provide visualisation of the rainfall data set while effectively and simply communicating patterns observed in the data-set in a spatial context. Providing time series this way can be useful trend detection and the detection of local precipitation anomalies within the record, useful in forecasting for policy making and helping going forward in future career opportuinties.
Data source
Station data is obtained from the homogenised Island of Ireland Precipitation (IIP) network which comprises 25 stations and a composite series covering the period 1850—2010. The IIP network is the second longest regional precipitation archive in the British Isles. (Noone, 2016; Noone_et al_., 2016).
Step 1
Firstly, a number of packages were installed which are the fundamental units of reproducible R code.These packages helped in producing this document and producing interactive components of the blog.
Step 2
Open librarys
install.packages.
library('tidyverse')
## Warning: package 'tidyverse' was built under R version 3.5.3
## -- Attaching packages -------------------------------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.2.1 v purrr 0.3.3
## v tibble 2.1.3 v dplyr 0.8.3
## v tidyr 1.0.0 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.4.0
## Warning: package 'ggplot2' was built under R version 3.5.3
## Warning: package 'tibble' was built under R version 3.5.3
## Warning: package 'tidyr' was built under R version 3.5.3
## Warning: package 'readr' was built under R version 3.5.3
## Warning: package 'purrr' was built under R version 3.5.3
## Warning: package 'dplyr' was built under R version 3.5.3
## Warning: package 'stringr' was built under R version 3.5.3
## Warning: package 'forcats' was built under R version 3.5.3
## -- Conflicts ----------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
Step 3 Open librarys
library("ggplot2")
library("plotly")
## Warning: package 'plotly' was built under R version 3.5.3
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
Step 4
Download station and rainfall data from Moodle to working directory, Open Rstudio, Open Rmarkdown, Set working directory, Check what working directory your loaded to and that set working directory has worked, Load rainfall data, View Station detail.
Below is the r codes used for step 4
load('rainfall.RData')
#View(stations)
Step 5
Use the head () function to check the contents of the two tables,
head(stations,n=25)
## # A tibble: 25 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 Ei~
## 2 Foulksmil~ 71 284100 118400 52.3 -6.77 Wexfo~ F Met Ei~
## 3 Mullingar 112 241780 247765 53.5 -7.37 Westm~ M Met Ei~
## 4 Portlaw 8 246600 115200 52.3 -7.31 Water~ P Met Ei~
## 5 Rathdrum 131 319700 186000 52.9 -6.22 Wickl~ RD Met Ei~
## 6 Strokesto~ 49 194500 279100 53.8 -8.1 Rosco~ S Met Ei~
## 7 Universit~ 14 129000 225600 53.3 -9.06 Galway UCG Met Ei~
## 8 Drumsna 45 200000 295800 53.9 -8 Leitr~ DAL Met Ei~
## 9 Ardara 15 180788. 394679. 54.8 -8.29 Doneg~ AR Briffa
## 10 Armagh 62 287831. 345772. 54.4 -6.64 Armagh A Armagh~
## # ... with 15 more rows
Table 1 ‘rain’ contains daily rainfall records for each weather station across Ireland,
Table 2 ‘stations’ contains attributes for each station, coordinate information, elevation, county locatation and a reference of the source for these attributes.
Step 6
Open lubridate librarys from installed packages.
library("lubridate")
## Warning: package 'lubridate' was built under R version 3.5.3
##
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
##
## date
Step 7
Filter data
rain %>% mutate(Date=ymd(paste0(Year,'-',Month,'-15'))) -> rain
rain %>% filter(Station=="Belfast") -> rain_belfast
rain %>% filter(Station=="Dublin Airport") -> rain_dublin_airport
rain %>% filter(Station=="University College Galway") -> rain_university_college_galway
rain %>% filter(Station=="Cork Airport") -> rain_cork_airport
Step 8
To create ggplot time series graphs for monthly rainfall, the x and y variables axis must be identified. R must also be told colour for the line, points size of font and title labels. The x-axis contains date for the period 1850-2014. The y axis contains rainfall in millimetres ‘mm’.
Below are the codes used for each station in formatting all four weather stations graphs.
plot_dublin_airport <- ggplot(rain_dublin_airport,aes(x=Date,y=Rainfall)) + geom_line(col='grey60') + geom_point(col='blue',size=0.5) + labs(title="Dublin Airport")
plot_university_college_galway <- ggplot(rain_university_college_galway,aes(x=Date,y=Rainfall)) + geom_line(col='grey60') + geom_point(col='blue',size=0.5) + labs(title="University College Galway")
plot_belfast <- ggplot(rain_belfast,aes(x=Date,y=Rainfall)) + geom_line(col='grey60') + geom_point(col='blue',size=0.5) + labs(title="Belfast")
plot_cork_airport <- ggplot(rain_cork_airport,aes(x=Date,y=Rainfall)) + geom_line(col='grey60') + geom_point(col='blue',size=0.5) + labs(title="Cork Airport")
Time Series Plots
Step 9
The following is the graphs of the weather stations at Belfast, Dublin Airport, University College Galway, and Cork Airport showing time series of rainfall on a monthly basis and that simultaneously changes the time window on the four time series.ggplot graphs are created using the %>% function.
plot_belfast %>% ggplotly()
As shown in the time series, most rainfall occurred at Belfast between 1850 - 2014 was between 50mm - 150mm. The highest recorded value was on 15/12/1978 at 329.5mm, with an increasing trend in precipitation since 2000.
plot_cork_airport %>% ggplotly()
As shown in the time series, most rainfall occurred at Cork Airport between 1850 - 2014 was between 50mm - 150mm. The highest recorded value was on 15/11/1889 at 460.5mm, with a decreasing trend in precipitation since the mid 1970’s.
plot_university_college_galway %>% ggplotly()
As shown in the time series, most rainfall occurred at University College Galway between 1850 - 2014 was between 50mm - 150mm. The highest recorded value was on 15/11/2009 at 329.4mm, with an increasing trend in precipitation since 1950.
plot_dublin_airport %>% ggplotly()
As shown in the time series, most rainfall occurred at Dublin Airport between 1850 - 2014 was between 25mm - 50mm, the lowest average out of all stations selected. The Highest recorded value was on 15/12/1978 at 217mm. Since 2000, a trend of increasing values in precipitation can be seen.
Monthly Graphs
Step 9
This code below shows the formula to fitler observations rainfall data post 1980 and it also will highlight the key stations. The code will create a ggplot graph of data and rainfall grouped by stations (Brunsdon, 2019). Particular weather stations can be highlighted in seagreen. The measurements of rainfall are in millimeters. The code tells R to filter the data (year>1980). It also tells R what colour to use. ggplot is used to create graphics
rain %>% filter(Year > 1980) %>% highlight_key(~Station,"Stations") -> rain_hs
ggplot(rain_hs,aes(x=Date,y=Rainfall,group=Station)) + geom_line(col='grey50') +
labs(y='Rainfall (mm total)') -> plot_ks
ggplotly(plot_ks,tooltip='Station',dynamicTicks = TRUE) %>%
highlight(on = "plotly_click", off = "plotly_doubleclick",color='green')
This time series highlights key stations all on one series. By clicking on the graph, each station is name is revealed with precipitation amounts on the x axis.
CODES
rain %>% filter(Year > 1980,Station=='Belfast') %>% highlight_key(~Year,"Year") -> rain_hy
ggplot(rain_hy,aes(x=Month,y=Rainfall,group=Year)) + geom_line(col='grey50') + geom_point() +
labs(y='Rainfall (mm total)') -> plot_ky
ggplotly(plot_ky,tooltip='Year') %>%
highlight(on = "plotly_click", off = "plotly_doubleclick",color='navy') %>%
layout(title="Belfast Monthly Rainfall (mm)")
This time series reveals precipitation amounts for Belfast weather station from the periods of 1980 to date. The highest value recorded during that period was in August 2008 at 250mm. Wettest months occur in January, August and October, with the driest months occurring in March, April and May.
CODES
rain %>% filter(Year > 1980,Station=='Cork Airport') %>% highlight_key(~Year,"Year") -> rain_hy
ggplot(rain_hy,aes(x=Month,y=Rainfall,group=Year)) + geom_line(col='grey50') + geom_point() +
labs(y='Rainfall (mm total)') -> plot_ky
ggplotly(plot_ky,tooltip='Year') %>%
highlight(on = "plotly_click", off = "plotly_doubleclick",color='navy') %>%
layout(title="Cork Airport Monthly Rainfall (mm)")
This time series reveals precipitation amounts for Cork Airport weather station from the periods of 1980 to date. The highest value recorded during that period was in February 1994 at 200mm. Wettest months occurred in December, January and February with the driest months occurring in April and May.
CODES
rain %>% filter(Year > 1980,Station=='Dublin Airport') %>% highlight_key(~Year,"Year") -> rain_hy
ggplot(rain_hy,aes(x=Month,y=Rainfall,group=Year)) + geom_line(col='grey50') + geom_point() +
labs(y='Rainfall (mm total)') -> plot_ky
ggplotly(plot_ky,tooltip='Year') %>%
highlight(on = "plotly_click", off = "plotly_doubleclick",color='navy') %>%
layout(title="Dublin Airport Monthly Rainfall (mm)")
This time series reveals precipitation amounts for Dublin Airport weather station from the periods of 1980 to date. The highest value recorded during that period was in August 2008 at 150mm. Wettest months occurred in June, July and August, with the driest months occurring in October and November.
CODES
rain %>% filter(Year > 1980,Station=='University College Galway') %>% highlight_key(~Year,"Year") -> rain_hy
ggplot(rain_hy,aes(x=Month,y=Rainfall,group=Year)) + geom_line(col='grey50') + geom_point() +
labs(y='Rainfall (mm total)') -> plot_ky
ggplotly(plot_ky,tooltip='Year') %>%
highlight(on = "plotly_click", off = "plotly_doubleclick",color='navy') %>%
layout(title="University College Galway Monthly Rainfall (mm)")
This time series reveals precipitation amounts for University College Galway weather station from the periods of 1980 to date. The highest value recorded during that period was in November 2009 at 350mm. Wettest months occurred in November, December and August, with the driest months occurring in March, April and July.
Conclusion
In conclusion, rain fall amounts varied across all four weather stations. Each station is geographically positioned in different areas of Ireland revealing varied precipitation rates across Ireland. University college Galway and Cork airport have the highest rates of precipitation with Dublin airport and Belfast precipitation rates lower. Due to westly locations of Cork and Galway with south west to westerly fronts know for higher precipitation amounts these locations are likely to recive higher amounts.
This type of data analysis is crucial for flood defences, geographical processes and economic policy’s relating to the climate change. From undertaken this project and creating a blog to reproduce my work I developed better R knowledge. I believe this has provide with a better understanding of data reproducibly and will be crucial going forward in my career.