October 28, 2016

Introduction

This presentation is on the monthly total rainfall(in millilitres) of the tropical island state of Singapore. Singapore is a sovereign state and global city in Southeast Asia and the world's only island city-state. Since it lies one degree north of the equator, it experiences the typical weather patterns of a tropical monsoon climate. With it's sophiscated measuring instruments, Singapore has one of the best utlities and facilities to observe any climate change (rainfall) in the region.

Two line plots will be generated. One that is monthly and one yearly. The yearly will contain information on years affected by El Nino and La Nina.

Data Source

Load Packages & Look at Dataset

library(dplyr)
library(plotly)
library(knitr)
library(lubridate)
#First read in the dataset
rainfall <- read.csv("rainfall-monthly-total.csv")
#Plus a summary
str(rainfall)
## 'data.frame':    417 obs. of  2 variables:
##  $ month         : Factor w/ 417 levels "1982-01","1982-02",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ total_rainfall: num  107.1 27.8 160.8 157 102.2 ...

Data Manipulation

Since we need yearly rainfall data, we need to sum up the monthly readings into yearly readings

rainfall_mth <- rainfall %>%
  mutate(temp = paste(month, "-01", sep = "")) %>%
  mutate(date = ymd(temp)) %>%
  select(date, total_rainfall)
rainfall_year <- rainfall_mth %>%
  mutate(year = year(date)) %>%
  select(year, total_rainfall) %>%
  group_by(year) %>%
  summarise(total_rainfall = sum(total_rainfall))

Plot by Year

Plot by Month

Appendix Yearly Plot Code Chunk

data1 <- rainfall_year[which(rainfall_year$year %in% "1997"),]
data2 <- rainfall_year[which(rainfall_year$year %in% "2015"),]
data3 <- rainfall_year[which(rainfall_year$year %in% "1982"),]
data4 <- rainfall_year[which(rainfall_year$year %in% "1988"),]
plot_ly(rainfall_year, x = ~year, y = ~total_rainfall, type = 'scatter', 
        mode = 'line+markers', hoverinfo = 'text',
        text = ~paste('Year: ', year,
                      '</br> Total rainfall(ml): ', total_rainfall)) %>%
  layout(title = "Line Plot of Total Rainfall by Year in Singapore",
        xaxis = list(title = "Year"), 
        yaxis = list(title = "Total Rainfall in millilitres")) %>%
  add_annotations(x = data1$year, y = data1$total_rainfall, 
                  text = "Very Strong El Nino", ax = 60, ay = -40) %>%
  add_annotations(x = data2$year, y = data2$total_rainfall, 
                  text = "Very Strong El Nino", ax = -30, ay = 30) %>%
  add_annotations(x = data3$year, y = data3$total_rainfall, 
                  text = "Very Strong El Nino", ax = 30, ay = 40) %>%
  add_annotations(x = data4$year, y = data4$total_rainfall, 
                  text = "Strong La Nina", ax = 30, ay = -30)

Appendix Monthly Plot Code Chunk

plot_ly(rainfall_mth, x = ~date, y = ~total_rainfall, type = 'scatter', 
        mode = 'line+markers',
        hoverinfo = 'text',
        text = ~paste('Date: ', month(date, label = TRUE, abbr = TRUE),
                      ' ', year(date),
                      '</br>Total rainfall(ml): ', total_rainfall)) %>%
  layout(title = "Line Plot of Total Rainfall by Month in Singapore",
        xaxis = list(title = "Month"), 
        yaxis = list(title = "Total Rainfall in millilitres"))