‘dygraphs’ is a JavaScript library useable within R which allows for the creation of interactive charts. The package is particularly useful in this case because it is capable of plotting large datasets and representing that information in a way that is intuitive, easily understood and easy to manipulate (Dygraphs, 2023). For the purposes of this work, dygraphs will be used to represent monthly rainfall data obtained from four Irish weather stations over the period 1850-2014. This data is continuous over the period for which it was recorded and then offers a valuable resource for data analysis.
In order to represent the data effectively, several packages were first loaded into the R Studio workspace:
The provided data was contained in the file ‘rainfall.RData’.
load("D:/rainfall.RData")
Before the data could be represented, it was necessary to group the relevant ‘Rainfall’ column using a time series:
rain %>% group_by(Year,Month)%>%
summarise(Rainfall=sum(Rainfall))%>% ungroup()%>% transmute(Rainfall) %>%
ts(start=c(1850,1),freq=12) -> rain_ts
## `summarise()` has grouped output by 'Year'. You can override using the
## `.groups` argument.
This made it possible to plot rainfall data over time using a dygraph, which included a rangeselector tool to allow manual adjustment of the time period shown:
rain_ts %>% dygraph(width=700,height=250) %>% dyRangeSelector()
This produces a graph showing the total rainfall for each month across the entire ‘rain_ts’ time series, with the option to shorten the range shown using the rangeselector tool. This is useful for gaining a broad overview of the available data but cannot represent stations individually. In order to achieve this it was then necessary to filter the available data, singling out the information relevant to the four stations on which this analysis focuses:
rain %>% group_by(Year,Month) %>% filter(Station=="Belfast") %>%
summarise(Rainfall=sum(Rainfall)) %>% ungroup() %>% transmute(Rainfall) %>%
ts(start=c(1850,1),freq=12) -> belfast_ts
## `summarise()` has grouped output by 'Year'. You can override using the
## `.groups` argument.
rain %>% group_by(Year,Month) %>% filter(Station=="Dublin Airport")%>%
summarise(Rainfall=sum(Rainfall))%>% ungroup() %>% transmute(Rainfall)%>%
ts(start=c(1850,1),freq=12) -> dublin_ts
## `summarise()` has grouped output by 'Year'. You can override using the
## `.groups` argument.
rain %>% group_by(Year,Month) %>% filter(Station=="University College Galway") %>%
summarise(Rainfall=sum(Rainfall))%>% ungroup() %>% transmute(Rainfall)%>%
ts(start=c(1850,1),freq=12) -> galway_ts
## `summarise()` has grouped output by 'Year'. You can override using the
## `.groups` argument.
rain %>% group_by(Year,Month) %>% filter(Station=="Cork Airport") %>%
summarise(Rainfall=sum(Rainfall))%>% ungroup() %>% transmute(Rainfall)%>%
ts(start=c(1850,1),freq=12) -> cork_ts
## `summarise()` has grouped output by 'Year'. You can override using the
## `.groups` argument.
Each station is now represented by a time series of the same name, which includes the associated rainfall data grouped by year and month. This provides a condensed group of data points that includes only information relevant to the stations for which it is needed. Using these new time series, each station can be shown as its own dygraph:
belfast_ts %>% dygraph(width=700,height=250, main='Belfast') %>% dyRangeSelector
dublin_ts %>% dygraph(width=700,height=250, main='Dublin Airport') %>% dyRangeSelector
galway_ts %>% dygraph(width=700,height=250, main='University College Galway') %>% dyRangeSelector
cork_ts %>% dygraph(width=700,height=250, main='Cork Airport') %>% dyRangeSelector
Each of the resulting dygraphs then shows one of the relevant stations, with data represented on a monthly basis and a rangeselector tool allowing for closer analysis of shorter periods within the time series. All stations can also be shown together, but this requires them to be represented using a single time series:
all_ts <- cbind(belfast_ts, dublin_ts, cork_ts,galway_ts)
From which a unified dygraph can be created:
all_ts %>% dygraph(width=700,height=250) %>% dyRangeSelector()
This represents data in the same way as the previous dygraphs, but shows all four stations together, represented by different colours. Alternatively, it is also possible to represent the stations together using separate dygraphs, by grouping them together:
belfast_ts %>% dygraph(width=700,height=250,group="all_group",main="Belfast")
dublin_ts %>% dygraph(width=700,height=250,group="all_group",main="Dublin Airport")
galway_ts %>% dygraph(width=700,height=250,group="all_group",main="University College Galway")
cork_ts %>% dygraph(width=700,height=250,group="all_group",main="Cork Airport") %>% dyRangeSelector()
This shows the data separately but links the rangeselector tool between the time series. It is possible to analyse the data in simpler ways as well:
summary(all_ts)
## belfast_ts dublin_ts cork_ts galway_ts
## Min. : 1.80 Min. : 1.50 Min. : 0.6 Min. : 0.40
## 1st Qu.: 55.60 1st Qu.: 37.30 1st Qu.: 54.4 1st Qu.: 65.25
## Median : 82.10 Median : 56.00 Median : 90.0 Median : 95.65
## Mean : 87.11 Mean : 61.43 Mean :100.0 Mean :101.43
## 3rd Qu.:113.72 3rd Qu.: 79.72 3rd Qu.:133.9 3rd Qu.:131.90
## Max. :329.50 Max. :217.00 Max. :460.5 Max. :329.40
The ‘summary’ command breaks down the data from each station showing their minimum, median, mean and maximum values, as well as their first and third quartile values. This can be useful when looking for more precise detail. In a similar way, a specific subset of the data can also be extracted using the ‘window’ command:
window(all_ts,c(2014,1),c(2014,12))
## belfast_ts dublin_ts cork_ts galway_ts
## Jan 2014 158.915663 101.6 200.4 206.03960
## Feb 2014 154.216867 88.5 240.5 233.86139
## Mar 2014 70.235294 53.7 107.8 106.36364
## Apr 2014 42.823529 34.2 104.6 39.45455
## May 2014 90.823529 91.5 70.6 120.72727
## Jun 2014 48.271605 36.2 85.7 66.33663
## Jul 2014 89.876543 35.0 43.6 70.29703
## Aug 2014 231.358025 173.0 88.3 140.79208
## Sep 2014 5.238095 26.5 19.7 19.27835
## Oct 2014 159.523810 90.2 180.1 167.11340
## Nov 2014 188.452381 140.9 192.0 154.32990
## Dec 2014 16.626506 55.9 58.9 168.21782
In this case the rainfall values from each station are listed by month for the year 2014. This command can be used to show data from any year or group of years needed, or for a period of only a few months.
Rainfall patterns across all four stations are broadly consistent, with some outliers identified within individual stations. This is expected given Ireland’s uniform temperate maritime climate, which facilitates broadly similar rainfall throughout the year across all parts of the island; some variation is evident due to prevailing winds and the presence or absence of mountainous terrain (Wesley Johnston, N.d.), but these are comparatively minor in contrast with those observed elsewhere (Ur-Rehman et al., 2019). Maximum rainfall values are then highest at Cork Airport (at 460.5mm in a single month), located in the region for which these factors are most evident (Wesley Johnston, N.d.).
By contrast, Dublin Airport received the least precipitation, likely owed to its situation on Ireland’s east coast, where prevailing weather systems are known to limit rainfall (Met Eireann, 2023). This may also explain why Belfast receives the next least precipitation overall, and University College Galway, on the west coast, more. The highest rainfall amounts were recorded predominantly in the winter months and in early spring, with the lowest amounts occurring, as might be expected, in high summer. However, rainfall was also generally low throughout late spring, potentially due to the movement of anticyclones from Greenland and continental Europe common during these months (Met Eireann, 2023). No obvious multi-year trends could be determined, with overall rainfall remaining apparently consistent across the time series. The lowest recorded rainfall month was in Galway in January 1938, at 0.6mm. This is interesting as it bucks the trend towards greater rainfall amounts falling in the winter. The highest was recorded in Cork, measuring 460.5mm in November 1899. Ultimately, the above data trends fell largely in line with what would be expected for Ireland.
Dygraphs (2023) dygraphs is a fast, flexible open source JavaScript charting library [online]. Available at: https://dygraphs.com/#:~:text=dygraphs%20is%20a%20fast%2C%20flexible,and%20interpret%20dense%20data%20sets. (accessed 8 January 2023).
Met Eireann (2023) Climate of Ireland [online]. Available at: https://www.met.ie/climate/climate-of-ireland (accessed 16 January 2023).
Ur-Rehman, S., Usmani, B. A., Ali Khan, M., Sadia, S., Elahi, A., Ali, S., Sarwat, Z., and Khan, K. (2019) A Model Investigation of Azores Impacts over France. International Journal of Advanced Research [online]. Available at: http://www.journalijar.com/article/26982/a-model-investigation-of-azores-impacts-over-france/ (accessed 16 January 2023).
Wesley Johnston (N.d.) Climate of Ireland, with maps [online]. Available at: https://www.wesleyjohnston.com/users/ireland/geography/climate.html#:~:text=Ireland%20enjoys%20a%20temperate%20maritime,with%20the%20occasional%20sunny%20spell. (accessed 16 January 2023).