Overview

#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.

Because of the recent policies around global warming, we plan to look at the issue with a focus on North America. We will analyze the average maximum and minimum temperatures from each state in the US and compare it against the historic average temperatures over the last century to see if we can shed light on the issue.

Source: [NOAA] (https://www.ncdc.noaa.gov/cag/statewide/mapping)

#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.

#Methods Help

Getting data

There are lots of places we can get climate data to answer your questions. The simplest would be to go to NOAA National Centers for Environmental Information (https://www.ncdc.noaa.gov/). There are all kinds of data here (regional, global, marine). Also, on the front page of the NOAA website there are also other websites that have climate data, such as: (https://www.climate.gov/), (https://www.weather.gov/), (https://www.drought.gov/drought/), and (https://www.globalchange.gov/). Obviously, you don’t have to use all of them but it might be helpful to browse them to get ideas for the development of your questions.

Alternatively, and more professionally, there are tons of packages that allow you to access data from R. See here for a great primer on accessing NOAA data with ‘R’. It is also a good introduction to API keys and their use.

Temperature Map

Summary

The graph shows a map of the United States with temperature data overlaid on it. The temperature data is represented using a color scale that ranges from blue (for colder temperatures) to red (for hotter temperatures), with white representing missing or invalid data. The legend at the bottom of the graph shows the color scale and labels it as “Temperature (°F)”.

Annual National Average Temperature

Summary

The above graph shows the annual national average temperature for the United States from 1895 to 2019. The blue line represents the actual temperature data for each year, while the orange line represents a linear regression fit to the data. The linear regression line indicates a positive trend in temperature over time, with a slope of approximately 0.02 degrees Fahrenheit per year. However, there is also a fair amount of variability in the data from year to year, as shown by the fluctuations in the blue line. Overall, the graph suggests that temperatures in the United States have been increasing over the past century, although the rate of increase has not been constant.

Annual Residential Energy Demand Temperature Index

Summary

The above graph shows the annual Residential Energy Demand Temperature Index (REDTI) for the United States from 1973 to 2021. The REDTI is an index that measures the impact of temperature on residential energy demand, with higher values indicating a greater impact. The blue bars represent the actual REDTI values for each year, while the orange line represents a linear regression fit to the data. The linear regression line indicates a slightly positive trend in REDTI over time, with a slope of approximately 0.04 units per year. However, there is also a fair amount of variability in the data from year to year, as shown by the fluctuations in the blue bars. Overall, the graph suggests that the impact of temperature on residential energy demand in the United States has been relatively stable over the past few decades, although there may be some long-term increase in the impact.

CO2 Data

Summary

The above graph shows boxplots of maximum average monthly land temperatures for the top five countries in terms of CO2 emissions over the past century. The countries included in the plot are China, United States, Russia, India, and France. The y-axis represents temperature in degrees Celsius and the x-axis represents the countries. Each boxplot displays the median (horizontal line inside the box), the interquartile range (box), and the range of the data (whiskers). The boxplots are colored according to the country represented, and there is a legend that identifies the color for each country. The plot has a light blue background and a title “Last century maximum average Monthly Land Temperatures”.

Conclusions

  1. What is the trend in temperature across the state? North part of the state tend to have low average Anomal temperature compare tothe south in the last century.
  2. Is there a trend in temperature in the last century? The energy demand for residential heating and cooling is increaed due to the abnormal temperature change. The average temperature has been steadily increased over the year of 1901 and 2000.
  3. What is the the role of human activity in global warming? Human plays an important part in climate change, combustion of fossil fuels and deforestation are the main causes to release CO2 in the atmosphere.
  4. What can we do to prevent global warming? Reduce the use of fossil fuels, today we have alternate methods to replace the use of fossil fuels. Individuals may reduce the use of non recyclable material
---
title: "Lab 2 Dashboard"
output:
  flexdashboard::flex_dashboard:
    orientation: rows
    social: menu
    source: embed
    vertical_layout: fill
  html_document:
    df_print: paged
---
Overview
=====================================
#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.

Because of the recent policies around global warming, we plan to look at the issue with a focus on North America. We will analyze the average maximum and minimum temperatures from each state in the US and compare it against the historic average temperatures over the last century to see if we can shed light on the issue.

Source: [NOAA] (https://www.ncdc.noaa.gov/cag/statewide/mapping)

#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.

#Methods Help

*Getting data*

There are lots of places we can get climate data to answer your questions. The simplest would be to go to NOAA National Centers for Environmental Information (https://www.ncdc.noaa.gov/). There are all kinds of data here (regional, global, marine). Also, on the front page of the NOAA website there are also other websites that have climate data, such as: (https://www.climate.gov/), (https://www.weather.gov/), (https://www.drought.gov/drought/), and (https://www.globalchange.gov/). Obviously, you don’t have to use all of them but it might be helpful to browse them to get ideas for the development of your questions.

Alternatively, and more professionally, there are tons of packages that allow you to access data from R. See here for a great primer on accessing NOAA data with ‘R’. It is also a good introduction to API keys and their use.

Temperature Map
=====================================
```{r}
library(maps)
library(mapproj)
library(scatterpie)
library(ggiraph)
library(dplyr)
library(ggplot2)
library(plotly)
library(rnoaa)
library(usmap)
library(gdtools)
library(readxl)
library(tidyr)

# Install and load the mapdata package
if (!requireNamespace("mapdata", quietly = TRUE)) {
  install.packages("mapdata")
}
library(mapdata)

# Download the file
url <- "https://www.ncdc.noaa.gov/cag/statewide/mapping/110-tavg-201906-12.csv"
filename <- "110-tavg-201906-12.csv"
if (!file.exists(filename)) {
  download.file(url, filename)
}

# Read the file
data <- read.csv(filename, skip=3, colClasses = c(Location="character", Value="numeric"))

# Clean up the data
data$region <- tolower(data$Location)
data <- data %>% select(-Location) %>% drop_na()

# Merge with the map data
state <- map_data("state")
temp <- left_join(state, data, by=c("region"="region"))

# Create the plot
mt <- ggplot(temp, aes(x = long, y = lat, group = group, fill = Value)) +
  geom_polygon(color = "white") +
  scale_fill_gradient(name="Temperature (°F)", low="blue", high="red", na.value="white") +
  labs(x="Longitude", y="Latitude") +
  coord_map() +
  theme_bw() +
  theme(panel.border = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        axis.line = element_blank(),
        legend.position = "bottom")

mt
```

### **Summary**
The graph shows a map of the United States with temperature data overlaid on it. The temperature data is represented using a color scale that ranges from blue (for colder temperatures) to red (for hotter temperatures), with white representing missing or invalid data. The legend at the bottom of the graph shows the color scale and labels it as "Temperature (°F)".

Annual National Average Temperature
=====================================
```{r}
library(tidyverse)

# Read data from URL and drop unneeded columns
data_2 <- read.csv(url("https://www.ncdc.noaa.gov/cag/national/time-series/110-tavg-1-6-1895-2019.csv?base_prd=true&begbaseyear=1901&endbaseyear=2000"), skip=4) %>% 
  select(Date, Value)

# Create the plot
ggplot(data_2, aes(x = Date, y = Value)) +
  geom_line() +
  geom_smooth(method = "lm", se = FALSE) +
  labs(title = "Annual National Average Temperature", x = "Year", y = "Temperature")
```

### **Summary**
The above graph shows the annual national average temperature for the United States from 1895 to 2019. The blue line represents the actual temperature data for each year, while the orange line represents a linear regression fit to the data. The linear regression line indicates a positive trend in temperature over time, with a slope of approximately 0.02 degrees Fahrenheit per year. However, there is also a fair amount of variability in the data from year to year, as shown by the fluctuations in the blue line. Overall, the graph suggests that temperatures in the United States have been increasing over the past century, although the rate of increase has not been constant.

Annual Residential Energy Demand Temperature Index
=====================================
```{r}
data_3 <- read.csv("https://www.ncdc.noaa.gov/societal-impacts/redti/USA/jun/1-month/data.csv", skip = 1)
ggplot(data_3, aes(x = Date, y = REDTI)) + 
  geom_col() + 
  geom_smooth(method = "lm", se = FALSE) + 
  labs(title = "Annual Residential Energy Demand Temperature Index", x = "Year", y = "REDTI")
```

### **Summary**
The above graph shows the annual Residential Energy Demand Temperature Index (REDTI) for the United States from 1973 to 2021. The REDTI is an index that measures the impact of temperature on residential energy demand, with higher values indicating a greater impact. The blue bars represent the actual REDTI values for each year, while the orange line represents a linear regression fit to the data. The linear regression line indicates a slightly positive trend in REDTI over time, with a slope of approximately 0.04 units per year. However, there is also a fair amount of variability in the data from year to year, as shown by the fluctuations in the blue bars. Overall, the graph suggests that the impact of temperature on residential energy demand in the United States has been relatively stable over the past few decades, although there may be some long-term increase in the impact.

CO2 Data
=====================================
```{r}
url <- "https://raw.githubusercontent.com/owid/co2-data/master/owid-co2-data.csv"
co2_data <- read.csv(url)

# Subset the data and remove rows with missing CO2 emissions data
countries_of_interest <- c("China", "United States", "Russia", "India", "France")
co2_data_filtered <- co2_data[co2_data$country %in% countries_of_interest & !is.na(co2_data$co2), ]

ggplot(co2_data_filtered, aes(x = country, y = co2, color = country)) +
  geom_boxplot() +
  labs(title = "CO2 emissions by country", x = "Country", y = "CO2 (metric tons per capita)") +
  theme_classic() +
  theme_light() +
  theme(panel.background = element_rect(fill = "lightblue")) +
  theme(plot.title = element_text(hjust = 0.5))
```

### **Summary**
The above graph shows boxplots of maximum average monthly land temperatures for the top five countries in terms of CO2 emissions over the past century. The countries included in the plot are China, United States, Russia, India, and France. The y-axis represents temperature in degrees Celsius and the x-axis represents the countries. Each boxplot displays the median (horizontal line inside the box), the interquartile range (box), and the range of the data (whiskers). The boxplots are colored according to the country represented, and there is a legend that identifies the color for each country. The plot has a light blue background and a title "Last century maximum average Monthly Land Temperatures".

Conclusions
=====================================
1. What is the trend in temperature across the state?
North part of the state tend to have low average Anomal temperature compare tothe south in the last century.
2. Is there a trend in temperature in the last century?
The energy demand for residential heating and cooling is increaed due to the abnormal temperature change. The average temperature has been steadily increased over the year of 1901 and 2000.
3. What is the the role of human activity in global warming?
Human plays an important part in climate change, combustion of fossil fuels and deforestation are the main causes to release CO2 in the atmosphere.
4. What can we do to prevent global warming?
Reduce the use of fossil fuels, today we have alternate methods to replace the use of fossil fuels. Individuals may reduce the use of non recyclable material