Introduction

Row

Overview

Climate change and science has been an issue for discussion and debate for at least the last decade. Climate data collection is currently being collected for areas all over the world. Policy decisions are based on the most recent analysis conducted on data extracted from huge online repositories of this data. Due to the inherent growth in the electronic production and storage of information, there is often a feeling of “information overload” or inundation when facing the process of quantitative decision making. As an analyst your job will often be to explore large data sets and develop questions or ideas from visualizations of those data sets.

The ability to synthesize large data sets using visualizations is a skill that all data scientists should have. In addition to this data scientists are called upon to present data syntheses and develop questions or ideas based on their data exploration. This lab should take you through the major steps in data exploration and presentation

Objective

The objective of this laboratory is to survey the available data, plan, design, and create an information dashboard/presentation that not only explores the data but helps you develop questions based on that data exploration. To accomplish this task you will have to complete a number of steps:

Identify what information interests you about climate change. Find, collect, organize, and summarize the data necessary to create your data exploration plan. Design and create the most appropriate visualizations (no less than 5 visualizations) to explore the data and present that information. Finally organize the layout of those visualizations into a dashboard (use the flexdashboard package) in a way that shows your path of data exploration. Develop four questions or ideas about climate change from your visualizations.

Row

Dates & Deliverables

You are responsible for submitting a link to your dashboard hosted on the Rpubs site. The dashboard must include the source_code = embed parameter.

The due date for this project is XX at the start of class. This assignment is worth 75 points, 3x a normal homework, the additional time should allow you to spend the neccessary effort on this assignment.

You are welcome to work in groups of ≤2 people. However, each person in a group must submit their own link to the assignment on Canvas for grading! Each team member can submit the same link to a single rpubs account, however it may be a good idea for each of you to post your own copy to rpubs in case you want to share it to prospective employers.

Row

Developed questions

  1. What is the general trends of temperature within US?

  2. Is there any temeperature difference among New York,Los Angeles,Chicago,Houston,Phoenix,Philadelphia,Charlotte? Do they share same trends?

  3. According to the charts, what is generally the hottest month and what is the coldest month in US?

  4. Which year has the highest average temperature in US (1900, 2000. 2013)?

column

Chart Analysis For US Major

Chart Analysis For US Major Cities

This sets of charts is the temperature trends of some major cities within United States. There is a clear upward trend of temperature for each of the cities, which proves the global warming trend.

Row

AverageTemperature in United States

This average temperature chart shows temperature change in United Sates by each month.

Month,-AverageTemperature

This view is showing average temperature of United States by each month in the past. From this chart we can get an idea of which month is general the warmest and which month is the coolest among the year.

Row

Average Temperature from 1750 to 2013 chart

This plot is showing the earth surface average temperature from 1750 to 2013 in USA. The color represents different temperatures. Blue is showing relatively low temperature and red is showing relatively high temperature. We clearly see a trend from this view that the termperature is increating through out the past hundreds of years.

Row

Average Temperature in United State

This visual shows the average US temperature from 1800 to 1900 with 25 years of interval. We can see that the general trend of temperature is indeed increasing.

Row

Temperature mapping in United States

Row

Chart 1

Chart 2

Chart 3

Row

From three charts on the left, we can clearly see that the temperature went up with time which reflects the global warming situation.

Conclusion

Based on the charts showing an upward trend in temperature, it can be concluded that global warming is a real and ongoing phenomenon. This trend is likely due to the increase in greenhouse gases in the atmosphere, primarily caused by human activities such as burning fossil fuels and deforestation. The consequences of global warming are numerous and severe, including rising sea levels, more frequent and intense natural disasters, and detrimental impacts on ecosystems and human health. It is important that we take action to mitigate the effects of global warming by reducing greenhouse gas emissions and transitioning to more sustainable practices.

Row

Developed questions answers

  1. What is the general trends of temperature within US?

Ans: The temeperature is going upward in the past hundreds of years within US. The average temperature increased around 4 degrees in the past 200 years.

  1. Is there any temeperature difference among New York, Los Angeles,Chicago,Houston,Phoenix,Philadelphia,Charlotte? Do they share same trends?

Ans: Yes, the average temperature is different among these cities. Houston and Phoenix share high temperature where Chicago and New York share low temperature. However, the general trends are all the same. The average temperature for all cities are going upwards.

  1. According to the charts, what is generally the hottest month and what is the coldest month in US?

Ans: From the charts, we can see that July has the highest temperature and January has the lowest average temperature in US.

  1. Which year has the highest average temperature in US (1900, 2000. 2013)?

Ans: temperature of 1900 is the lowest and the temperature for 2013 is highest. Temperature of 2000 is in the middle. Generally speaking, the temperature is going upward.

---
title: "ANLY 512 - Lab 2 Dashboard"
Name: "Bolun Lu"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    social: menu
    source: embed
    html_document:
    df_print: paged
    pdf_document: default
---

# Table of Contents {.sidebar}

* Introduction
  
* Chart Analysis For US Major Cities 

* AverageTemperature in United States 

* Month,-AverageTemperature

* Average Temperature from 1750 to 2013 chart

* Average Temperature in United States

* Temperature mapping in United States

* Conclusion


# **Introduction**

Row 
-------------------------------------
    
### **Overview** 

Climate change and science has been an issue for discussion and debate for at least the last decade. Climate data collection is currently being collected for areas all over the world. Policy decisions are based on the most recent analysis conducted on data extracted from huge online repositories of this data. Due to the inherent growth in the electronic production and storage of information, there is often a feeling of “information overload” or inundation when facing the process of quantitative decision making. As an analyst your job will often be to explore large data sets and develop questions or ideas from visualizations of those data sets.

The ability to synthesize large data sets using visualizations is a skill that all data scientists should have. In addition to this data scientists are called upon to present data syntheses and develop questions or ideas based on their data exploration. This lab should take you through the major steps in data exploration and presentation

### **Objective** 

The objective of this laboratory is to survey the available data, plan, design, and create an information dashboard/presentation that not only explores the data but helps you develop questions based on that data exploration. To accomplish this task you will have to complete a number of steps:

Identify what information interests you about climate change.
Find, collect, organize, and summarize the data necessary to create your data exploration plan.
Design and create the most appropriate visualizations (no less than 5 visualizations) to explore the data and present that information.
Finally organize the layout of those visualizations into a dashboard (use the flexdashboard package) in a way that shows your path of data exploration.
Develop four questions or ideas about climate change from your visualizations.


 Row
-------------------------------------
 
### **Dates & Deliverables**
You are responsible for submitting a link to your dashboard hosted on the Rpubs site. The dashboard must include the source_code = embed parameter.

The due date for this project is XX at the start of class. This assignment is worth 75 points, 3x a normal homework, the additional time should allow you to spend the neccessary effort on this assignment.

You are welcome to work in groups of ≤2
 people. However, each person in a group must submit their own link to the assignment on Canvas for grading! Each team member can submit the same link to a single rpubs account, however it may be a good idea for each of you to post your own copy to rpubs in case you want to share it to prospective employers.


 Row
-------------------------------------
     
### **Developed questions** 
1. What is the general trends of temperature within US?

2. Is there any temeperature difference among New York,Los Angeles,Chicago,Houston,Phoenix,Philadelphia,Charlotte? Do they share same trends?

3. According to the charts, what is generally the hottest month and what is the coldest month in US?

4. Which year has the highest average temperature in US (1900, 2000. 2013)?

```{r Data Loading}

library(flexdashboard)
library(quantmod)
library(plyr)
library(dplyr)
library(tidyverse) 
library(lubridate)
library(DataExplorer)
library(highcharter)
library(viridisLite)
library(ggplot2)
library(dygraphs) 
library(xts) 
library(readxl)
library(maps)
library(viridis)
library (animation)


city <- read.csv("~/Documents/ANLY/ANLY512/lab2/archive/GlobalLandTemperaturesByCity.csv")
Country <- read.csv("~/Documents/ANLY/ANLY512/lab2/archive/GlobalLandTemperaturesByCountry.csv")
state <- read.csv("~/Documents/ANLY/ANLY512/lab2/archive/GlobalLandTemperaturesByState.csv")
GT <- read.csv("~/Documents/ANLY/ANLY512/lab2/archive/GlobalTemperatures.csv")
MajorCity <- read.csv("~/Documents/ANLY/ANLY512/lab2/archive/GlobalLandTemperaturesByMajorCity.csv")


MajorCityUS<-city[city$Country == "United States",]
MajorCityUS$dt <-as.Date(MajorCityUS$dt)
MajorCityUS$Year <- format(MajorCityUS$dt,"%Y")
MajorCityUS$Month <- format(MajorCityUS$dt,"%m")

CityUS <-city[city$Country == "United States",]
CityUS$dt <-as.Date(CityUS$dt)
CityUS$Year <- format(CityUS$dt,"%Y")
CityUS$Month <- format(CityUS$dt,"%m")
```


column{.tabset}
----------------------------------------------------------------------------------------------




# Chart Analysis For US Major


### Chart Analysis For US Major Cities {data-width=2000}
```{r Major Cities}

Major_Cities <- c("New York","Los Angeles","Chicago","Houston","Phoenix","Philadelphia","Charlotte")

MajorCityUS %>%
  filter(City %in% Major_Cities) %>%
  group_by(City, Year) %>%
  summarise(avg_temp = mean(AverageTemperature)) %>%
  ggplot(aes(Year, avg_temp, color = avg_temp)) + 
    geom_point() +
    scale_x_discrete(breaks = c(1820, 2013)) +
    facet_grid(~City) +
    labs(x = "Year", y = "Average Temperature", color = "Temperature",
         title = "Temperature Change over the last two centuries",
         subtitle = "For US Cities") +
    theme_bw() +
    theme(panel.spacing = unit(0.5, "lines"), 
          axis.text.x = element_text(angle = 90, hjust = 1),
          panel.grid.major.y = element_blank(),
          panel.grid.minor.y = element_blank(),
          axis.ticks = element_blank(),
          legend.position = "top",
          legend.text = element_text(size = 8),
          legend.key.height = unit(40, "pt"),
          legend.key.width = unit(70, "pt"),
          plot.background = element_rect(fill = "azure1"))

```


### 
This sets of charts  is the temperature trends of some major cities within United States. There is a clear upward trend of temperature for each of the cities, which proves the global warming trend.

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

# AverageTemperature in United States {data-width=2000}

```{r Chart}
US <- Country %>% filter(Country=="United States")
US$dt <-as.Date(US$dt)
US$Year <- format(US$dt,"%Y")
US$Month <- format(US$dt,"%m")
US %>% filter(!is.na(AverageTemperature))  %>% 
  group_by(Year) %>% mutate(length_of_year= length(Year)) %>% group_by(Month) %>% mutate(avg_tempMonth= mean(AverageTemperature)) %>%
  filter(length_of_year==12) %>% 
  ggplot(aes(Month,AverageTemperature,group = Year, color = as.numeric(dt))) + 
  geom_line(alpha= 0.2) + 
  geom_line(aes(Month,avg_tempMonth),color= "grey60",alpha = 1) +
  scale_x_discrete(labels=c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec"))+
  theme(legend.position = "bottom", axis.title = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.minor.y = element_blank(),
        plot.background = element_rect(fill = "antiquewhite"),
        axis.text = element_text(size = 12),
        plot.title = element_text(size= 18,face = "bold")) + 
  ggtitle("Average Temperature in United States", subtitle = "1770 to 2013 ") 


```

### 
This average temperature chart shows temperature change in United Sates by each month. 


# Month,-AverageTemperature {data-width=2000}

```{r }
US_AVG_TEMP <- Country %>% filter(Country=="United States")

US_AVG_TEMP$dt <-as.Date(US_AVG_TEMP$dt)
US_AVG_TEMP$Year <- format(US_AVG_TEMP$dt,"%Y")
US_AVG_TEMP$Month <- format(US_AVG_TEMP$dt,"%m")
US_AVG_TEMP <- na.omit(US_AVG_TEMP)
US_AVG_TEMP <- filter(US_AVG_TEMP, dt >= 1800, Country == 'United States')

ggplot(US_AVG_TEMP)+
  aes(dt,AverageTemperature,color=reorder(Month,-AverageTemperature))+
  geom_point()+
  geom_smooth(method = 'loess')+
  labs(x="Year",y="Average Temperature in United State")


```


### 
This view is showing average temperature of United States by each month in the past. From this chart we can get an idea of which month is general the warmest and which month is the coolest among the year.

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


#  Average Temperature from 1750 to 2013 chart {data-width=2000}

```{r }
rm <-city[city$Country == "United States",]
rm$dt <- ymd(rm$dt)
rm$Year <- year(rm$dt)
rm$Month <- month(rm$dt)

#Aggregating the average temperatures year wise
avg_US <- aggregate(AverageTemperature ~ Year, FUN=mean, data = rm)
ggplot(avg_US)+
  aes(Year,AverageTemperature,color = Year)+
  geom_point()+
  labs(x="year",y="Average Temperature")+
  scale_color_gradient(low="steelblue1", high="red")+
  ggtitle("Earth Surface Average Temperature from 1750 to 2013 in United States ")


```

### 
This plot is showing the earth surface average temperature from 1750 to 2013 in USA. The color represents different temperatures. Blue is showing relatively low temperature and red is showing relatively high temperature. We clearly see a trend from this view that the termperature is increating through out the past hundreds of years.


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


# Average Temperature in United State {data-width=2000}

```{r Bar chart }
# Create a vector of years to filter by
years <- c(1800, 1825, 1850, 1875, 1900, 1925, 1950, 1975, 1900)
# Filter the data and calculate the mean temperature for each year
duration <- avg_US %>%
  filter(Year %in% years) %>%
  group_by(Year) %>%
  summarise(Temp = mean(AverageTemperature))

# Convert the Year column to a factor
duration$Year <- as.factor(duration$Year)

# Create a bar plot of the average temperature for each year
ggplot(data = duration, aes(x = Year, y = Temp, fill = Year)) +
  geom_bar(stat = "identity") +
  ggtitle(" US Average Temperature for 25-Year Intervals (1800 to 1900)") +
  xlab("Year") +
  ylab("Average Temperature") +
  theme_bw()

```


This visual shows the average US temperature from 1800 to 1900 with 25 years of interval. We can see that the general trend of temperature is indeed increasing.
 
Row
------------------------------------------------

# Temperature mapping in United States

```{r, sage=FALSE, warning=FALSE}

state$dt <- as.Date(state$dt)
state$Year <- format.Date(state$dt,format = "%Y")
state$Month <- format.Date(state$dt,format = "%m")
state.usa <- state %>% filter(Country == 'United States')

avg.temp1855 = state.usa %>% filter(Year == 1855) %>% group_by(State) %>% summarise(avg.temp.1855 = mean(AverageTemperature,na.rm = T))
usa.map = map_data("state")
a= unique(usa.map$region)
avg.temp1855$State = tolower(avg.temp1855$State)
avg.temp1855$State[11] = a[10]
usa.map = merge(x=usa.map,y=avg.temp1855,by.x = "region",by.y = "State",all.x = TRUE)

avg.temp1900 = state.usa %>% filter(Year == 1900) %>% group_by(State) %>% summarise(avg.temp.1900 = mean(AverageTemperature,na.rm = T))
avg.temp1900$State = tolower(avg.temp1900$State)
avg.temp1900$State[11] = a[10]
usa.map = merge(x=usa.map,y=avg.temp1900,by.x = "region",by.y = "State",all.x = TRUE)

avg.temp2000 = state.usa %>% filter(Year == 2000) %>% group_by(State) %>% summarise(avg.temp.2000 = mean(AverageTemperature,na.rm = T))
avg.temp2000$State = tolower(avg.temp2000$State)
avg.temp2000$State[11] = a[10]
usa.map = merge(x=usa.map,y=avg.temp2000,by.x = "region",by.y = "State",all.x = TRUE)

avg.temp2013 = state.usa %>% filter(Year == 2013) %>% group_by(State) %>% summarise(avg.temp.2013 = mean(AverageTemperature,na.rm = T))
avg.temp2013$State = tolower(avg.temp2013$State)
avg.temp2013$State[11] = a[10]
usa.map = merge(x=usa.map,y=avg.temp2013,by.x = "region",by.y = "State",all.x = TRUE)



usa.map$change1900 <- (usa.map$avg.temp.1900 - usa.map$avg.temp.1855)*100/usa.map$avg.temp.1855
usa.map$change2000 <- (usa.map$avg.temp.2000 - usa.map$avg.temp.1855)*100/usa.map$avg.temp.1855
usa.map$change2013 <- (usa.map$avg.temp.2013 - usa.map$avg.temp.1855)*100/usa.map$avg.temp.1855



plot1900 <- ggplot() + geom_polygon(data = usa.map,aes(x=long,y=lat,group = group,fill = change1900),col = "white")+
  scale_fill_continuous(low="light blue",high = "red",limits = c(-0.15,122),name = "Percentage Change in Average Temperature")+
    #theme_nothing(legend = T)+
  theme(legend.position = "bottom")+
  labs(title = "Year - 1900")+
  coord_map("albers",  at0 = 45.5, lat1 = 29.5)

plot2000 <- ggplot() + geom_polygon(data = usa.map,aes(x=long,y=lat,group = group,fill = change2000),col = "white")+
  scale_fill_continuous(low="light blue",high = "red",limits = c(-0.15,122),name = "Percentage Change in Average Temperature")+
    #theme_nothing(legend = T)+
  theme(legend.position = "bottom")+
  labs(title = "Year - 2000")+
  coord_map("albers",  at0 = 45.5, lat1 = 29.5)

plot2013 <- ggplot() + geom_polygon(data = usa.map,aes(x=long,y=lat,group = group,fill = change2013),col = "white")+
  scale_fill_continuous(low="sky blue",high = "red",limits = c(-0.15,122),name = "Percentage Change in Average Temperature")+
  #theme_nothing(legend = T)+
  theme(legend.position = "bottom")+
  labs(title = "Year - 2013")+
  coord_map("albers",  at0 = 45.5, lat1 = 29.5)


```

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

### Chart 1 
```{r }
plot1900
```

### Chart 2
```{r }
plot2000
```


### Chart 3
```{r }
plot2013
```


Row 
-------------------------------------
From three charts on the left, we can clearly see that the temperature went up with time which reflects the global warming situation.


# **Conclusion**

Based on the charts showing an upward trend in temperature, it can be concluded that global warming is a real and ongoing phenomenon. This trend is likely due to the increase in greenhouse gases in the atmosphere, primarily caused by human activities such as burning fossil fuels and deforestation. The consequences of global warming are numerous and severe, including rising sea levels, more frequent and intense natural disasters, and detrimental impacts on ecosystems and human health. It is important that we take action to mitigate the effects of global warming by reducing greenhouse gas emissions and transitioning to more sustainable practices.

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

### **Developed questions answers**

1. What is the general trends of temperature within US?

Ans: The temeperature is going upward in the past hundreds of years within US. The average temperature increased around 4 degrees in the past 200 years.

2. Is there any temeperature difference among New York, Los Angeles,Chicago,Houston,Phoenix,Philadelphia,Charlotte? Do they share same trends?

Ans: Yes, the average temperature is different among these cities. Houston and Phoenix share high temperature where Chicago and New York share low temperature. However, the general trends are all the same. The average temperature for all cities are going upwards.

3. According to the charts, what is generally the hottest month and what is the coldest month in US?

Ans: From the charts, we can see that July has the highest temperature and January has the lowest average temperature in US.

4. Which year has the highest average temperature in US (1900, 2000. 2013)?

Ans: temperature of 1900 is the lowest and the temperature for 2013 is highest. Temperature of 2000 is in the middle. Generally speaking, the temperature is going upward.