GLOBAL TEMPERATUE CHANGE

##Row

Monthly Global Land Temperature from 1750 to 2015

Monthly Land Average Temperature By Season With Uncertainty

Annual Gloabl Land Average Temperature from 1750 to 2015

BY SEASON

Row

Gloabl Winter Average Temperature

Gloabl Spring Average Temperature

Row

Gloabl Summer Average Temperature

Gloabl Fall Average Temperature

BY COUNTRY

Column

China Average Annual Land Temperature

USA Average Annual Land Temperature

BY CONTINENT

Row

Asia Temperature Change

Europe Temperature Change

South America Temperature Change

Row

North America Temperature Change

Africa Temperature Change

Oceania Temperature Change

CONCLUSION

Conclusion

Based on the visualizations of the Gloabal Temperature dataset and Gloabal Temperature by Country dataset, we could realize that climate change is a fact rather than a conspiracy. Average temperature by season and country are both increasing for the last two centuries.

Further Questions

This analysis confirmed the idea of global warming, but also leave us some more questins about climate change.

  1. The global temperature increase seems obvious in the visualization, but how significant it is statistically?

  2. Do all countries having an increasing average temperature overtime? If not, which ones have the decreasing average temperature?

  3. Average temperature in winter and fall increase more than those in summer and spring, what’s the reason behind?

  4. Some continents seem to be affected by global warming more than other, why is that?

---
title: "Climate Change Analysis"
author: "Yueying Zhang"
date: "June 05 2019"
output: 
  flexdashboard::flex_dashboard:
    social: menu
    source: embed
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)

#load packages
library(readr)
library(ggplot2)
library(tidyverse)
library(ggthemes)
library(plotly)

#Read in datasets 
GlobalLandTemperaturesByCountry <- read_csv("GlobalLandTemperaturesByCountry.csv")
GlobalTemperatures <- read_csv("GlobalTemperatures.csv")

#See the descriptive stats of global temperatures
summary(GlobalTemperatures)
#the last six variavles are all NAs, so we should delete them
GlobalTemperatures_new = GlobalTemperatures[,c(1:3)]

##Seperate the date variables into months for global, so we could group by years and seasons

GlobalTemperatures_new = GlobalTemperatures_new %>% separate(dt, sep="-", into = c("year", "month", "day"))

spring = GlobalTemperatures_new %>% filter(month == '03'|month == '04'|month == '05') %>% mutate('spring')
summer = GlobalTemperatures_new %>% filter(month == '06'|month == '07'|month == '08') %>% mutate('summer')
fall = GlobalTemperatures_new %>% filter(month == '09'|month == '10'|month == '11') %>% mutate('fall')
winter = GlobalTemperatures_new %>% filter(month == '12'|month == '01'|month == '02') %>% mutate('winter')

#change the new variables name to 'season; so we could combine data framews
names(spring)[6] = paste("season")
names(summer)[6] = paste("season")
names(fall) [6] = paste("season")
names(winter)[6] = paste("season")

gt = rbind(spring,summer,fall,winter)
gt = gt[with(gt, order(year, month)),]
gt$dt = GlobalTemperatures$dt
```

GLOBAL TEMPERATUE CHANGE
=====================================

##Row {.tabset .tabset-fade}
-----------------------------------------------------------------------

### Monthly Global Land Temperature from 1750 to 2015 

```{r }
##See the average temp over years
ggplotly(ggplot(gt, aes(dt,LandAverageTemperature)) + 
  geom_line(color = 'grey') +
  geom_smooth(color = 'orange') +
  theme_classic()+
  labs(title = 'Monthly Global Land Average Temperature From 1750 To 2015', x = 'Date', y = 'Land Average Temperature'))

```

### Monthly Land Average Temperature By Season With Uncertainty
```{r}
ggplotly(ggplot(gt, aes(dt,LandAverageTemperature, col = season)) + geom_line() + geom_smooth() + 
  labs(title = 'Monthly Land Average Temperature by Season', x = 'Year', y = 'Land Average Temperature')+
  geom_errorbar(aes(ymin = LandAverageTemperature - LandAverageTemperatureUncertainty,
                    ymax = LandAverageTemperature + LandAverageTemperatureUncertainty)))
```

### Annual Gloabl Land Average Temperature from 1750 to 2015

```{r}
#gt is the new total data frame
#Plot the average land temp per year

gt$year = as.numeric(gt$year)
per_year = gt %>% group_by(year) %>% summarise(average = mean(LandAverageTemperature))
ggplotly(ggplot(per_year,aes(year,average)) + 
  geom_line(color = "gold") + 
  geom_smooth(color = "lightblue") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_x_continuous(breaks=seq(1750, 2015, 10)) + 
  labs(title = 'Annual Gloabl Average Land Temperature', x = 'Year', y= 'Temperature'))

```



BY SEASON
=====================================

Inputs {.sidebar}
-------------------------------------

From the plots we could see that the average land temperature of all four seasons have been increasing since record. Winter and fall seems to be the most impacted ones. We are experiencing warmer winter and fall than people living 200 years ago.


Row
-------------------------------------
### Gloabl Winter Average Temperature

```{r}
winter_average = gt %>% filter(season =='winter') %>% group_by(year) %>% summarise(winter_average = mean(LandAverageTemperature))  
  
  ggplotly(ggplot(winter_average, aes(year, winter_average)) +
  geom_line(color = 'grey')+ 
  geom_smooth(color = "grey28") +
  theme_classic() +
  labs(title = 'Gloabl Winter Average Temperature', x = 'Year', y= 'Temperature'))
```


   
### Gloabl Spring Average Temperature

```{r}
spring_average = gt %>% filter(season =='spring') %>% group_by(year) %>% summarise(winter_average = mean(LandAverageTemperature))  
  
ggplotly(ggplot(spring_average,aes(year, winter_average)) +
  geom_line(color = 'lightgreen')+
  geom_smooth(color = "springgreen4") + 
  theme_classic() +
  labs(title = 'Gloabl Spring Average Temperature', x = 'Year', y= 'Temperature'))
```   
   
Row
-------------------------------------    
### Gloabl Summer Average Temperature

```{r}
summer_average = gt %>% filter(season =='summer') %>% group_by(year) %>% summarise(winter_average = mean(LandAverageTemperature)) 
  
ggplotly(ggplot(summer_average,aes(year, winter_average)) +
  geom_line(color = 'lightpink')+
  geom_smooth(color = "hotpink") +
  theme_classic() +
  labs(title = 'Gloabl Summer Average Temperature', x = 'Year', y= 'Temperature'))
```


### Gloabl Fall Average Temperature

```{r}
fall_average = gt %>% filter(season =='fall') %>% group_by(year) %>% summarise(winter_average = mean(LandAverageTemperature)) 

ggplotly(ggplot(fall_average,aes(year, winter_average)) +
  geom_line(color = 'firebrick')+
  geom_smooth(color = "brown4")+
  theme_classic() +
  labs(title = 'Gloabl Fall Average Temperature', x = 'Year', y= 'Temperature'))
```




BY COUNTRY
=====================================

Inputs {.sidebar}
-------------------------------------

There're over 200 countries in the dataset, let's take a closer look at certain countries. I picked China and USA here. From the plots we could see that the average land temperature of both China and US are increasing since 19th century. 

Column
-------------------------------------
###China Average Annual Land Temperature
```{r}
GlobalTemperaturesByCountry_new = GlobalLandTemperaturesByCountry %>% separate(dt, sep="-", into = c("year", "month", "day"))

#set the season

springcountry = GlobalTemperaturesByCountry_new %>% filter(month == '03'|month == '04'|month == '05') %>% mutate('spring')
summercountry= GlobalTemperaturesByCountry_new %>% filter(month == '06'|month == '07'|month == '08') %>% mutate('summer')
fallcountry = GlobalTemperaturesByCountry_new %>% filter(month == '09'|month == '10'|month == '11') %>% mutate('fall')
wintercountry = GlobalTemperaturesByCountry_new %>% filter(month == '12'|month == '01'|month == '02') %>% mutate('winter')

#change the variable name
names(springcountry)[7] = paste("season")
names(summercountry)[7] = paste("season")
names(fallcountry) [7] = paste("season")
names(wintercountry)[7] = paste("season")

#conbime the whole df back together
gtcountry = rbind(springcountry,summercountry,fallcountry,wintercountry)
gtcountry = gtcountry[with(gtcountry, order(Country, year,month)),]

gtcountry$year = as.numeric(gtcountry$year)
#the final one: China Average Annual Land Temperature
chinatemp = gtcountry %>% filter(Country == 'China') %>% group_by(year) %>% summarise(yearly_average = mean(AverageTemperature))

ggplotly(ggplot(chinatemp,aes(year,yearly_average)) + 
  geom_line(color = 'pink') + 
  geom_smooth(color = 'pink', fill = 'pink') +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_x_continuous(breaks=seq(1800, 2015, 10)) +
  labs(title = 'China Average Annual Land Temperature From 1800 - 2015', x = 'Year', y = "Average Temperature") +
  theme_tufte())
```
 
###USA Average Annual Land Temperature

```{r}
#The final one:US Average Annual Land Temperature
ustemp = gtcountry %>% filter(Country == 'United States') %>% group_by(year) %>% summarise(yearly_average = mean(AverageTemperature)) 
ggplotly(ggplot(ustemp,aes(year,yearly_average)) + 
  geom_line(color = 'lightblue2') + 
  geom_smooth(color = 'lightblue2', fill = 'lightblue2') +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_x_continuous(breaks=seq(1800, 2015, 10)) +
  labs(title = 'US Average Annual Land Temperature From 1800 - 2015', x = 'Year', y = "Average Temperature") +
  theme_tufte())
```


BY CONTINENT
=====================================

Row 
-------------------------------------
   
### Asia Temperature Change

```{r}
#Asia temp change
asiatemp = GlobalTemperaturesByCountry_new %>% filter(Country == 'Asia') %>% group_by(year) %>% summarize(averagetemp = mean(AverageTemperature))
asiatemp$year = as.numeric(asiatemp$year) 
ggplotly(ggplot(asiatemp,aes(year,averagetemp)) + 
  geom_line(color = "#E69F00") + 
  geom_smooth(color = "#E69F00", fill = "#E69F00") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_x_continuous(breaks=seq(1800, 2015, 10)) +
  labs(title = 'Asia Average Annual Land Temperature From 1800 - 2015', x = 'Year', y = "Average Temperature") +
  theme_tufte())
```   
 
### Europe Temperature Change
    
```{r}
#Europe temp change
eutemp = GlobalTemperaturesByCountry_new %>% filter(Country == 'Europe') %>% group_by(year) %>% summarize(averagetemp = mean(AverageTemperature))
eutemp$year = as.numeric(eutemp$year) 
ggplotly(ggplot(eutemp,aes(year,averagetemp)) + 
           geom_line(color = "#56B4E9") + 
           geom_smooth(color = "#56B4E9", fill = "#56B4E9") +
           theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
           scale_x_continuous(breaks=seq(1800, 2015, 15)) +
           labs(title = 'Europe Average Annual Land Temperature From 1800 - 2015', x = 'Year', y = "Average Temperature") +
           theme_tufte())
```

###South America Temperature Change
```{r}
#south America temp change
satemp = GlobalTemperaturesByCountry_new %>% filter(Country == 'South America') %>% group_by(year) %>% summarize(averagetemp = mean(AverageTemperature))
satemp$year = as.numeric(satemp$year) 
ggplotly(ggplot(satemp,aes(year,averagetemp)) + 
           geom_line(color = "#009E73") + 
           geom_smooth(color = "#009E73", fill = "#009E73") +
           theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
           scale_x_continuous(breaks=seq(1800, 2015, 10)) +
           labs(title = 'South America Average Annual Land Temperature From 1800 - 2015', x = 'Year', y = "Average Temperature") +
           theme_tufte())
```


Row 
-------------------------------------

###North America Temperature Change
```{r}
#North America temp change
natemp = GlobalTemperaturesByCountry_new %>% filter(Country == 'North America') %>% group_by(year) %>% summarize(averagetemp = mean(AverageTemperature))
natemp$year = as.numeric(natemp$year) 
ggplotly(ggplot(natemp,aes(year,averagetemp)) + 
           geom_line(color = "#F0E442") + 
           geom_smooth(color = "#F0E442", fill = "#F0E442") +
           theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
           scale_x_continuous(breaks=seq(1800, 2015, 15)) +
           labs(title = 'North America Average Annual Land Temperature From 1800 - 2015', x = 'Year', y = "Average Temperature") +
           theme_tufte())
```


###Africa Temperature Change

```{r}
#Africa temp change
aftemp = GlobalTemperaturesByCountry_new %>% filter(Country == 'Africa') %>% group_by(year) %>% summarize(averagetemp = mean(AverageTemperature))
aftemp$year = as.numeric(aftemp$year) 
ggplotly(ggplot(aftemp,aes(year,averagetemp)) + 
           geom_line(color = "#0072B2") + 
           geom_smooth(color = "#0072B2", fill = "#0072B2") +
           theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
           scale_x_continuous(breaks=seq(1800, 2015, 10)) +
           labs(title = 'Africa Average Annual Land Temperature From 1800 - 2015', x = 'Year', y = "Average Temperature") +
           theme_tufte())
```


###Oceania Temperature Change
```{r}
#Oceania temp change
octemp = GlobalTemperaturesByCountry_new %>% filter(Country == 'Oceania') %>% group_by(year) %>% summarize(averagetemp = mean(AverageTemperature))
octemp$year = as.numeric(octemp$year) 
ggplotly(ggplot(octemp,aes(year,averagetemp)) + 
           geom_line(color = "#D55E00") + 
           geom_smooth(color = "#D55E00", fill = "#D55E00") +
           theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
           scale_x_continuous(breaks=seq(1800, 2015, 10)) +
           labs(title = 'Oceania Average Annual Land Temperature From 1800 - 2015', x = 'Year', y = "Average Temperature") +
           theme_tufte())
```



CONCLUSION
=====================================

### Conclusion

Based on the visualizations of the Gloabal Temperature dataset and Gloabal Temperature by Country dataset, we could realize that climate change is a fact rather than a conspiracy. Average temperature by season and country are both increasing for the last two centuries. 


### Further Questions

This analysis confirmed the idea of global warming, but also leave us some more questins about climate change.

1. The global temperature increase seems obvious in the visualization, but how significant it is statistically?

2. Do all countries having an increasing average temperature overtime? If not, which ones have the decreasing average temperature?

3. Average temperature in winter and fall increase more than those in summer and spring, what's the reason behind?

4. Some continents seem to be affected by global warming more than other, why is that?