Introduction

The package ‘Dygraph’ in R allows for the generation of interactive time series graphs. Singular or multiple graphs can be created by a few simple lines of R code.This package makes it easier to explore and analyse time series. The aim of this RPubs page is to describe the development of a dygraph containing four weather stations rainfall data for the locations, Dublin Airport, Cork Airport, University College Galway and Belfast, at a monthly mean time frame for the period 1850-2014. Using a grouping code, the four locations dygraphs will be linked, due to this linkage, a range selector will be generated. This will allow simultaneous movement to occur among the four dygraphs and making it easier for the user to pinpoint a certain period of time in all of the graphs. The four dygraphs will show the difference in the amount of precipitation which fell in the different locations for the 164 years recorded. The following sections will contain (1) an explanation of the data used, (2) the code that was used to generate the time series, (3) the embedded dygraphs with a range selector and ,finally, (4) a discussion of any pattern identified in the data for the four locations.

Data Used

The rainfall data supplied ranged from the time period 1850-2014 on a monthly mean basis as an R binary file, this was already sorted into a format which allowed it to be loaded into RStudio. The data was imported into RStudio via right clicking the rainfall data file i.e. where it was downloaded to, selecting the open with option and selecting RStudio. The rainfall data now loaded, is available to be manipulated into the individual dygraphs.

Code Used

The dygraph package is available in the Comprehensive R Archive Network (CRAN) in RStudio, to begin the dplyr and the dygraph libraries were loaded.

library(dplyr)
## Warning: package 'dplyr' was built under R version 3.2.3
## 
## 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(dygraphs)

As the rainfall data is in the format of an R binary file, this was convered to a CVS (Comma separated values) file, as this is the format in which RMarkdown will allow for the rainfall data to be loaded.

Rainfall <- read.csv("C:/Users/Alice/Desktop/ChrisB/rain.csv", sep="")

To isolate a certain station such as the four chosen for this analysis, a line of code is needed to ungroup those stations from others which are also contained within the rain data file. The following code will do this and states, taking the rainfall data file generated above, group all the data into months and years, then from that extract the specific station (e.g. Dublin Airport), then from that create a summary of the rainfall data, then ungroup and transmute the rainfall data, and take the starting date to be 1850 located in column 1 in the data spreadsheet for the 12 months and call this extracted stations data a certain name (e.g. dubs_ts). This code will generate the monthly mean time series for that specific station.

Rainfall %>%  group_by(Year,Month) %>% filter(Station=="Dublin Airport") %>%
  summarise(Rainfall=sum(Rainfall)) %>% ungroup %>% transmute(Rainfall) %>%
  ts(start=c(1850,1),freq=12) ->  dub_ts
Rainfall %>%  group_by(Year,Month) %>% filter(Station=="Belfast") %>%
  summarise(Rainfall=sum(Rainfall)) %>% ungroup %>% transmute(Rainfall) %>%
  ts(start=c(1850,1),freq=12) ->  bel_ts

Rainfall %>%  group_by(Year,Month) %>% filter(Station=="Cork Airport") %>%
  summarise(Rainfall=sum(Rainfall)) %>% ungroup %>% transmute(Rainfall) %>%
  ts(start=c(1850,1),freq=12) ->  cor_ts

Rainfall %>%  group_by(Year,Month) %>% filter(Station=="University College Galway") %>%
  summarise(Rainfall=sum(Rainfall)) %>% ungroup %>% transmute(Rainfall) %>%
  ts(start=c(1850,1),freq=12) ->  gal_ts

After generating the individual stations into monthly mean time series, these now need to be grouped/linked to create the dygraphs, containing a range selector control which has the ability to simultaneously change the time window on the four time series. The following command states, that taking the file name (e.g. dubs_ts) created above, generate a dygraph with the width being 800 and the height being 130 and group it as a name (e.g. dub_belf), with the heading of the dygraph called for the station name for example Dublin, and finally create a range selector which will allow the simultaneous movement between the 4 locations dygraphs.

dub_ts %>% dygraph(width=800,height=130,group="four",main="Dublin") 

cor_ts %>% dygraph(width=800,height=130,group="four",main="Cork Airport") 

gal_ts %>% dygraph(width=800,height=130,group="four",main="University College Galway") 

bel_ts %>% dygraph(width=800,height=170,group="four",main="Belfast") %>% dyRangeSelector

Discussion

Time series graphs commonly display random fluctuations, but they also show gradual shifts or movement towards an increase or decrease in this case, in precipitation over time. Precipitation has a tendency to have a chaotic behaviour through time and this is reflected within the above dygraph, precipitation is shown to fluctuate over time, however there is a small degree of increase throughout the years. Depending on the location of the station, there seems to be a difference in the amount of rain recorded at each of the stations. The rainfall follows a similar trend but the amount fallen is dissimilar.

Dublin Airport is located along the east coast of Ireland, this station has recorded a reasonable lesser amount of precipitation than that of the other three stations. This is due to its location, as the rain clouds has to pass over the island having just travelled over Atlantic Ocean as these clouds move, they lose precipitation as rainfall. By the time the clouds have reached the Dublin station the amount of water available for precipitation has reduced significantly. Belfast also shows to have received a higher amount of rainfall than Dublin but less than the other two. Like Dublin, Belfast is also situated along the east coast but is higher in latitude. Cork has recorded a lesser amount of rainfall than compared to that which fell at the University College Galway, but more than Dublin and Belfast, these two stations are located along the south coast and the west coast, both being exposed the Atlantic Ocean.

Looking at precipitation in cycles, approximate 40 year periods were chosen as to capture the natural variation associated with natural phenomenon, the period 1850-1890 shows the lowest recordings of precipitation recorded in the 164 years, however towards the end of this period rates were increasing. Seasonal fluctuations can be seen with Belfast showing to have a reduced amount of rainfall, with Dublin, Galway and Cork following in an increasing volume trend. The 1891-1931 period showed an increase in the amount of rainfall to that of the previous 40 year cycle, seasonal fluctuation is also seen with precipitations chaotic behaviour evident. A dissimilar volume was recorded between the stations with Dublin being the lowest, followed in succession by Belfast, Galway and Cork. The period 1973-2014 showed an increase to that of the last two cycles, with precipitations chaotic nature masking the increase of the seasonal variation, however, there is a noticeable slight increase. As with the previous stations, a dissimilar amount fell between the stations with Dublin receiving the least, followed by Belfast, Galway and Cork. All the approximate 40 year time periods follow the similar trend with the amount of rain that fell at which station, a noticeable similar trend was seen between the data sets with spikes in rainfall occurring on one dygraph seen in the other three, this also occurs with reduced precipitation rates.

This analysis shows nature is chaotic over the 164 years with a slight increase in precipitation through the years. The stations located along the south and west coast received a higher amount of rainfall due it orientation to the Atlantic Ocean, the other two stations located along the east coasts received a lower volume of rain due to both stations being sheltered along the east by the English Channel and the fact that it is on the opposite side of the country from the prevailing winds, with moisture being lost as it travels across the island. Each station even though they received a difference in the amount, follow a similar trend in the time in which has it has fallen. Despite the fact that each station received a difference in the amount of precipitation, a similar trend is followed over time. An increase in both the magnitude and the frequency of precipitation is related to climate change.