Loading libraries

library(dplyr)
## 
## Attaching package: 'dplyr'
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(knitr)
library(dygraphs)
library(xts)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## 
## Attaching package: 'xts'
## 
## The following objects are masked from 'package:dplyr':
## 
##     first, last
library(htmlwidgets)

Setting knitr options

opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE, cache = FALSE,
               error = FALSE)

Loading file.

file.2 <- "Programming Assignment 1 Data New/ExcelFormattedGISTEMPData2CSV.csv"

Read the file

data.2 <- read.csv(file.2, header=TRUE, stringsAsFactors = FALSE)

Some data cleaning data.2

data.2 <- rename(data.2, Global = Glob, Nothern = NHem, Southern = SHem,
       lat24N.90N = X24N.90N, lat24S.24N = X24S.24N, lat90S.24S = X90S.24S,
       lat64N.90N = X64N.90N, lat44N.64N = X44N.64N, lat24N.44N = X24N.44N,
       latEQU.24N = EQU.24N, lat24S.EQU = X24S.EQU, lat44S.24S = X44S.24S,
       lat64S.44S = X64S.44S, lat90S.64S = X90S.64S)

selecting complete cases

datacompl2 <- complete.cases(data.2)

data.4 <- data.2[datacompl2,]

Selecting data for plot

plotData <- select(data.4, one_of(c("Global", "Nothern",
                                    "Southern")))
data.4$Year <- as.character(data.4$Year)

data.4$Year <- as.Date(data.4$Year, format = "%Y")

rownames(plotData) <- data.4$Year

Coverting to time series

plotData <- as.xts(plotData)

Drawing the plot

plot3 <- dygraph(plotData, #main = "Global temperature anomalies", 
    xlab = "Year", ylab = "Temperature anomaly (C x 100)") %>%
    dyOptions(titleHeight = 28, rightGap = 40) %>%
    dySeries("Global", color = "black") %>%
    dySeries("Nothern", color = "#800000") %>%
    dySeries("Southern", color = "#0066CC") %>%
    dyHighlight() %>%
    dyLegend(labelsSeparateLines = TRUE, labelsDiv = "labels") %>%
    dyAxis("x", valueRange = c(1880, 2015)) %>%
    dyAxis("y", valueRange = c(-40, 90)) %>%
    dyRoller(rollPeriod = 10) %>%
    dyRangeSelector(dateWindow = c("1900-07-31", "2000-07-31")) %>%
    dyEvent(date = "1950-1-01", "Benchmark start", labelLoc = "top") %>%
    dyEvent(date = "1980-1-01", "Benchmark start", labelLoc = "top")

Global temperature anomalies


plot3


Note: The chart title and legend box was added by using html tags in R Markdown file.