Introduction:

Global warming poses the biggest threat to our planet. Hence, now more tan ever, it is extremely important to visualize the changing environmental measures of our planet so that we can re-iterate on the rapid change that has been happening, and tell the story to the world with our visuals.

In doing so, we ask the following 4 re-iterative questions based on our visualizations:

  1. Can we conclude that the predictor of global warming i.e. CO2 levels are rising?
  2. Can we conclude that the ‘result’ of global warming i.e. temperature anomolies are more frequent with the passage of time?
  3. Can we conclude that the ‘result’ of global warming i.e. rising sea levels are anologous to Ice melting in the poles?
  4. Can we conclude that the above three measures are somewhat related i.e. Rising CO2 Levels, Rising Temperatures, and Rising Sea Levels?

Source: NOAA

Rising CO2

Question: Can we conclude that the predictor of global warming i.e. CO2 levels are rising?

Rising Temperature Anomolies

Question: Can we conclude that the ‘result’ of global warming i.e. temperature anomolies are more frequent with the passage of time?

Global Mean Sea Level

Question: Can we conclude that the ‘result’ of global warming i.e. rising sea levels are anologous to Ice melting in the poles?

Conclusion and Questions

The purpose of this analysis is to show a tangible but drastic change that global warming has resulted in.

In doing so, we ask the following 4 re-iterative questions based on our visualizations:

  1. Can we conclude that the predictor of global warming i.e. CO2 levels are rising?
  2. Can we conclude that the ‘result’ of global warming i.e. temperature anomolies are more frequent with the passage of time?
  3. Can we conclude that the ‘result’ of global warming i.e. rising sea levels are anologous to Ice melting in the poles?
  4. Can we conclude that the above three measures are somewhat related i.e. Rising CO2 Levels, Rising Temperatures, and Rising Sea Levels?
---
title: "ANLY 512 - Lab 2"
subtitle: _Data Exploration and Analysis Laboratory_
author: _Ayesha Khan_
date: _`r Sys.Date()`_

output: 
  flexdashboard::flex_dashboard:
    storyboard: true
    source: embed
    orientation: columns
    vertical_layout: fill
    df_print: paged
---

```{r setup, include=FALSE}

knitr::opts_chunk$set(echo = FALSE)
library(flexdashboard)
knitr::opts_chunk$set(echo = TRUE)
library(maps)
library(readr)
library(plotly)
library(dygraphs)
library(ggplot2)
library(lubridate)
#install.packages("mapproj")
library(mapproj)
```

Introduction:
===================================== 
Global warming poses the biggest threat to our planet. Hence, now more tan ever, it is extremely important to visualize the changing environmental measures of our planet so that we can re-iterate on the rapid change that has been happening, and tell the story to the world with our visuals.

In doing so, we ask the following 4 re-iterative questions based on our visualizations:

1) Can we conclude that the predictor of global warming i.e. CO2 levels are rising?
2) Can we conclude that the 'result' of global warming i.e. temperature anomolies are more frequent with the passage of time?
3) Can we conclude that the 'result' of global warming i.e. rising  sea levels are anologous to Ice melting in the poles?
4) Can we conclude that the above three measures are somewhat related i.e. Rising CO2 Levels, Rising Temperatures, and Rising Sea Levels?



Source: [NOAA](https://www.climate.gov/maps-data/dataset/extreme-weather-records-state-data-table)


Rising CO2
=======================================================================
Question: Can we conclude that the predictor of global warming i.e. CO2 levels are rising?
```{r, echo = FALSE, message = FALSE}
# get data
acd = read.table("ftp://aftp.cmdl.noaa.gov/products/trends/co2/co2_mm_mlo.txt", header = FALSE, col.names = c("Year","Month","Decimal_Date","Average","Interpolated","Trend","Days"), skip = 70)

# reformat date
acd$Average = replace(acd$Average, acd$Average == -99.99, NA)
acd$Days = replace(acd$Days, acd$Days == -1, NA)
scaled_acd = acd
scaled_acd$Interpolated = scale(acd$Interpolated)
scaled_acd_time_series = ts(scaled_acd$Interpolated, frequency = 12, start = c(1958,3))

# plot
plot(scaled_acd_time_series, main = "Monthly Mean Atmospheric Carbon Dioxide Levels", xlab = "Year", ylab="Monthly Mean Atmospheric Carbon Dioxide Level")
```



Rising Temperature Anomolies
=======================================================================
Question: Can we conclude that the 'result' of global warming i.e. temperature anomolies are more frequent with the passage of time?
```{r, echo = FALSE, message = FALSE}
# get data
gmt = read.table("http://climate.nasa.gov/system/internal_resources/details/original/647_Global_Temperature_Data_File.txt", header = TRUE, col.names = c("Year","Annual_Mean","Five_Year_Mean"),skip = 4, nrows=136)

# reformat date 
gmt[,3] = as.numeric(as.character(gmt[,3]))
scaled_gmt = gmt
scaled_gmt[,2] = scale(gmt$Annual_Mean)
scaled_gmt[,3] = scale(gmt$Five_Year_Mean)
scaled_gmt_time_series = ts(scaled_gmt$Five_Year_Mean, frequency = 1, start=c(1880))

# plot
plot(scaled_gmt_time_series, main = "Temperature Anomalies", xlab = "Year", ylab="Annual 5-Year Mean Temperature Anomaly")
```


Global Mean Sea Level
=======================================================================
Question: Can we conclude that the 'result' of global warming i.e. rising  sea levels are anologous to Ice melting in the poles?
```{r, echo = FALSE, message = FALSE}
gmsl <- read.table("http://sealevel.colorado.edu/files/2018_rel1/sl_ns_global.txt", header = FALSE, skip = 1)
colnames(gmsl) <- c("year", "msl")

# reformat date
gmsl$datetime <- date_decimal(gmsl$year)
gmsl$date <- as.Date(format(gmsl$datetime, "%Y-%m-%d"), format = "%Y-%m-%d")

# plot
ggplot(gmsl, aes(date, msl)) +  
    geom_line(color = "pink") +
    geom_point(color = "red", size = 1) +
    stat_smooth(span = 0.2) +   
    stat_smooth(method = "lm") +    
    xlab("Year") +
    ylab(expression(paste(Delta, " MSL (mm)"))) +
    ggtitle("Global Mean Sea Level") +
    theme_bw()
```


Conclusion and Questions
====================================
The purpose of this analysis is to show a tangible but drastic change that global warming has resulted in. 

In doing so, we ask the following 4 re-iterative questions based on our visualizations:

1) Can we conclude that the predictor of global warming i.e. CO2 levels are rising?
2) Can we conclude that the 'result' of global warming i.e. temperature anomolies are more frequent with the passage of time?
3) Can we conclude that the 'result' of global warming i.e. rising  sea levels are anologous to Ice melting in the poles?
4) Can we conclude that the above three measures are somewhat related i.e. Rising CO2 Levels, Rising Temperatures, and Rising Sea Levels?