Load the necessary packages
library(dplyr)
library(dygraphs)
library(lubridate)
library(xts)
Read the data.
d <- read.csv("data/1880-2014.csv", skip=2)
NOAA_ann_link <- "http://www.ncdc.noaa.gov/cag/time-series/global/globe/land_ocean/ytd/12/1880-2014.csv"
d <- read.csv(NOAA_ann_link, skip = 2)
Calculate the decadal annomaly:
pd <- d %>% mutate(decade = Year %/% 10) %>%
group_by(decade) %>%
mutate(dvalue = mean(Value)) %>%
mutate(date = ymd(paste0(Year, "-01-01"))) %>% ungroup
Convert to xts and plot using dygraph. Try zooming in, it is awesome :)
pdx <- xts(pd %>% select(-Year,-date, -decade), order.by = pd$date)
pdx %>% dygraph(main = "NOAA Land and Sea Temperature Annual Anomaly Trend") %>%
dySeries("dvalue", stepPlot = TRUE, color = "blue", label = "Decadal avg anomaly") %>%
dySeries("Value", color = "gray", label = "Annual anomaly")