---
title: "EDA on Global Temperatures"
author: "Kowshik Kumar B"
output:
flexdashboard::flex_dashboard:
orientation: columns
social: [ "menu" ]
source: embed
vertical_layout: scroll
---
```{r setup, include=FALSE}
library(flexdashboard)
library(dygraphs)
library(pdfetch)
library(ggplot2)
library(dplyr)
library(lubridate)
library(ggbeeswarm)
library(gridExtra)
library(viridis)
library(timeSeries)
library(gridExtra)
library(scales)
library(zoo)
library(fBasics)
library(evir)
library(TH.data)
library(lubridate)
library(dplyr)
library(plotly)
library(shiny)
library(tidyverse)
library(tidyquant)
library(lawn)
library(timetk)
library(readr)
TempCity <- read_csv("GlobalLandTemperaturesByCity.csv")
TempCityUSA<-TempCity[TempCity$Country=="United States",]
TempCityUSA$dt <-as.Date(TempCityUSA$dt)
TempCityUSA$Year <- format(TempCityUSA$dt,"%Y")
TempCityUSA$Month <- format(TempCityUSA$dt,"%m")
TempCityUSA<-na.omit(TempCityUSA)
TempCountry<-read_csv("GlobalLandTemperaturesByCountry.csv")
TempCountryUSA<-TempCountry[TempCountry$Country=="United States",]
TempCountryUSA$dt <-as.Date(TempCountryUSA$dt)
TempCountryUSA$Year <- format(TempCountryUSA$dt,"%Y")
TempCountryUSA$Month <- format(TempCountryUSA$dt,"%m")
TempCountryUSA<-na.omit(TempCountryUSA)
```
# Introduction {.sidebar}
* This Dashboard helps us explore different visualizations for climatic changes in USA and further draws analysis for it's major cities.
* The data is taken from https://www.kaggle.com/berkeleyearth/climate-change-earth-surface-temperature-data which is a subset of NOAA's citation.
* From the data visualizations, it is clear that the average temperatures have drastically across the years whose visuals are analyzed for Overall USA and it's major cities.
* The first visualization explores monthly temperature analysis across a difference of one century of USA and it is clear that the average temperature ranges have increased in 2010's compared to 1910's.
* In the second visualization, it is clear that average temperatures have been changing which has been visualized every 50 years.
* Further from the visual plots of climatic changes for major cities of USA, the average temperatures of Atlanta, Chicago and New York were low and were substantially changing over the years from 1800 to 2010.
* In Conclusion, We can clearly state that the temperatures have been changed over the years and if we observe the months span yearly visuals, it is clearly evident that the temperatures have been increasing each and every year.
# Climatic analysis for overall USA
Column {.tabset}
-----------------------------------------------------------------------
### Monthly Temperatures analysis for century between Now (2010) and Then (1910)
```{r}
TempCityUSA %>% filter(Year==1910 | Year==2010) %>% ggplot(aes(AverageTemperature,Month,color=AverageTemperature)) +
geom_quasirandom() +
scale_colour_viridis(option = "D")+
facet_grid(Year ~.) +
coord_flip()
```
### Yearly Temperatures analysis for every 50 years span
```{r}
TempCityUSA %>% filter( Year==1850 | Year==1900 | Year==1950 | Year==2000) %>% ggplot(aes(AverageTemperature,Year,color=AverageTemperature)) +
geom_quasirandom() + scale_colour_viridis(option = "C")
```
# Climatic Changes for Major Cities in USA
Column {.tabset}
-----------------------------------------------------------------------
### Temperatures changes over last two centuries for major cities in USA
```{r}
ImpCities<-c("Chicago","New York","Los Angeles","Atlanta")
TempCityUSA %>% filter(City %in% ImpCities) %>% group_by(City,Year) %>% summarise(avg_temp= mean(AverageTemperature)) %>% ggplot(aes(Year,avg_temp,color=avg_temp)) +
geom_point() +
scale_x_discrete( breaks = c(1800,2010))+
scale_color_viridis(option="B")+
theme(axis.text.x = element_text(angle = 90, hjust = 1),
panel.spacing = unit(0.6, "lines"),legend.position = "top",
legend.text=element_text(size=8),
panel.grid.major.y = element_blank(),panel.grid.minor.y = element_blank(),
axis.ticks.y = element_blank(),
axis.ticks.x = element_blank(),
plot.background = element_rect(fill = "#EFF2F4"),
legend.key.height = unit(10, "pt"),
legend.key.width = unit(70, "pt"))+
ggtitle("Temperature Change over last two centuries",subtitle = "Indian Cities")+
ylab("Temperature")+labs(color="Temperature")+
facet_grid(~City )
```
### Heatmap of Major cities for each month's Temperatures
```{r}
TempCityUSA %>% filter(City %in% ImpCities) %>% group_by(City,Month) %>%
summarise(avg_temp= mean(AverageTemperature,na.rm=T)) %>% ggplot(aes(Month,reorder(City,avg_temp),fill=avg_temp)) +geom_tile()+
scale_fill_viridis(option = "C") + labs(fill= "Temperature ")+ ylab("Cities")+
theme(panel.grid= element_blank()) + ggtitle("Heatmap!",subtitle = "Cities,Months and Temperature")
```
### Density plot for Temperatures changes for major cities in USA
```{r}
USAImpCities<-TempCityUSA %>% filter(City %in% ImpCities)
ggplot(USAImpCities,aes(AverageTemperature,label=paste(City,""))) + geom_density(fill="grey") +
facet_grid(City ~.) +
ylab("")+
geom_text(aes(0,0.2),fontface="plain",hjust=0.1,color="gray20")+
theme_minimal()+
ggtitle("Density plot of average temperatures")+
theme(text = element_text(face = 'plain', color = '#3A3F4A'),
axis.text.y = element_blank(),axis.ticks.y = element_blank(),
axis.line.y = element_blank(),strip.background = element_blank(),
strip.text.y = element_blank(),axis.line.x = element_blank(),
plot.background = element_rect(fill = "#EFF2F4"),
plot.title = element_text(size = 14, face = "bold", colour = "gray20", vjust = -1))
```