---
title: "Climate Change Analysis"
author: "Qiong Duan"
date: "November 5, 2019"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
```
Global Climate Change Indicators {data-orientation=columns}
==========================================================================
Sidebar {.sidebar}
-----------------------------------------------------------------------
### Earth's climate is warming!
The Global Surface Temperature is Rising
Global average temperature is one of the most-cited indicators of global climate change, and shows an increase of approximately 0.83°C since the early 20th Century.
U.S. Climate Extremes are Increasing
The Climate Extremes Index (CEI) value for the contiguous United States is an objective way to determine whether extreme events are on the rise. The graph shows that the the number of extreme climate events (those which place among the most unusual of the historical record) has been rising over the last four decades.
Glacier Volume is Shrinking
Warming temperatures lead to the melting of glaciers and ice sheets. The total volume of glaciers on Earth is declining sharply. Glaciers have been retreating worldwide for at least the last century; the rate of retreat has increased in the past decade.
Column {.tabset .tabset-fade data-height=500}
-----------------------------------------------------------------------
### Global Surface Temperature
```{r}
library(plyr)
library(reshape)
library(RCurl)
NOAA_ann_link <- "https://www.ncdc.noaa.gov/cag/global/time-series/globe/land_ocean/ytd/12/1880-2019/data.csv"
n <- read.table(NOAA_ann_link, skip = 4, sep = ",", dec=".",
row.names = NULL, header = T, as.is = T, colClasses = rep("numeric",2),
col.names = c("yr", "anom") )
## Find last report year and last anomaly value
num_rows <- nrow(n)
NOAA_last_yr <- as.integer(n[num_rows,1])
NOAA_last_anom <- signif(n[nrow(n),2],2)
# Decade calculations
dec_mean<- as.numeric(14)
dec_st <- as.numeric(14)
dec_end <- as.numeric(14)
base_yr <- 1880
n$dec_n <- (as.numeric((n$yr - base_yr) %/% 10) * 10) + base_yr
# df <- data.frame(df, dec_n)
for (i in 1:13) {dec_st[i] = base_yr+ i*10
dec_sub <- subset(n, dec_n == dec_st[i], na.rm=T)
dec_mean[i] <- mean(dec_sub$anom)
}
dec_st[14] <- 2020 # Need to have for last step line across decade
dec_mean[14] <- dec_mean[13]
dec<- data.frame(dec_st, dec_mean)
# Trend chart function
plot_func<- function() {
par(las=1); par(ps=12); par(oma=c(2.5,1,1,1)); par(mar=c(2.5,4,2,1))
p_xmin <- 1880; p_xmax <- n[num_rows,1]
title <- paste("Global Land and Sea Temperature Annual Anomaly Trend (", p_xmin, " - ", NOAA_last_yr,")", sep="")
plot(n$yr, n$anom, type = "l", col = "grey",
xlim = c(p_xmin, p_xmax), ylab = "Degrees Celsius (Base Period: 1901-2000)",
xlab="", main = title,cex.main = 0.8, cex.lab = 0.7, cex.axis = 0.7)
points(NOAA_last_yr, NOAA_last_anom, col = "red", pch=19)
last_pt <- paste( NOAA_last_yr, " @ ", NOAA_last_anom, "°C",sep="")
points(dec$dec_st, dec$dec_mean, type="s", col="blue")
## add legend
legend(1882,0.6, c("Decadal Avg Anomaly" ,"Annual anomaly", last_pt), col = c("blue", "grey", "red"),
text.col = "black", lty = c(1,1,0),pch=c(0,0,16),pt.cex=c(0,0,1),
merge = F, bg = "white", bty="o", cex = .65, box.col="white")
out <- paste("NOAA Annual Temperature Anomaly nData updated through: " , NOAA_last_yr, sep="")
t_pos <- p_xmin + 0.5*(p_xmax-p_xmin)
text(t_pos, -0.55, out, cex = 0.65, adj = 0)
data_source <- paste("Data Source: ", NOAA_ann_link, sep="")
# Plot Annotation
mtext(data_source,1,0, cex = 0.5, adj=0.5, outer=T)
}
##########################################################################################
plot_func()
```
### U.S. Climate Extremes Index (CEI)
```{r}
library(reshape2)
library(ggplot2)
NOAA_ann_link <- "https://www.ncdc.noaa.gov/extremes/cei/graph/us/01-12/1/data.csv"
n <- read.table(NOAA_ann_link, skip = 1, sep = ",", dec=".",
row.names = NULL, header = T, as.is = T, colClasses = rep("numeric",2),
col.names = c("yr", "Above","Below") )
n["Below"] = -n["Below"]
n.long<-melt(n,id=c("yr"))
ggplot(data = n.long,aes(x = yr, y = value, fill = variable))+
geom_bar(stat = "identity")+
theme_bw(base_size = 8)+
theme(plot.title = element_text(face = "bold", size=9, hjust = 0.5),legend.position = c(0.9, 0.2)) +
labs(x = "Year",
y = "% Above or Below Normal",
title = "Contiguous U.S. Extremes in Maximum Temperature Annual (1910-2018)",
fill = '')
```
### Glacier Volume
```{r}
library(grid)
library(gridExtra)
library(ggplot2)
NOAA_ann_link <- "https://www.ncdc.noaa.gov/snow-and-ice/extent/sea-ice/G/9.csv"
n <- read.table(NOAA_ann_link, skip = 3, sep = ",", dec=".",
row.names = NULL, header = T, as.is = T, colClasses = rep("numeric",2),
col.names = c("Year", "Ice","Anomaly") )
grob <- grobTree(textGrob("Mean: 24.90", x=0.85, y=.6, hjust=0,
gp=gpar(col="red", fontsize=9, fontface="italic")))
ggplot(data = n,aes(x = Year, y = Ice))+
geom_line()+
ylim(22,27)+
theme_bw(base_size = 8)+
theme(plot.title = element_text(face = "bold", size=9, hjust = 0.5),legend.position = c(0.9, 0.2)) +
labs(x = "Year",
y = "Sea Ice Extent (million square kilometer)",
title = "September Global Sea Ice Extent (1979-2019)",
fill = '') +
geom_hline(yintercept=24.9,linetype="dashed", color = "red") +
annotation_custom(grob)
```
Human Influence {data-orientation=columns}
==========================================================================
Sidebar {.sidebar}
-----------------------------------------------------------------------
### Greenhouse Effect
A greenhouse gas (sometimes abbreviated GHG) is a gas that absorbs and emits radiant energy within the thermal infrared range. Greenhouse gases cause the greenhouse effect, which is the major cause of the global warming.
The concentration of CO2 in the atmosphere has increased by roughly 35 percent since the start of the industrial revolution. Globally, over the past several decades, about 80 percent of human-induced CO2 emissions came from the burning of fossil fuels, while about 20 percent resulted from deforestation and associated agricultural practices.
From the graph, we can find the country who emitted the most CO2 in 2016 is China, while Australia has the largest per capita number. At the same time, US ranks #2 in both of the total and per capita CO2 emission volume in 2016. We should think about how to control our CO2 emissions to prevent global warming.
Row
-----------------------------------------------------------------------
### Total CO2 Emissions by Country
```{r}
library(readxl)
library(RColorBrewer)
myPalette <- brewer.pal(5, "Set2")
data <- read_excel('co2 emission 2016.xlsx')
label = paste(data$Country,data$`CO2 emissions (total)`," ")
pie(data$`CO2 emissions (total)`, labels= label, border="white", col=myPalette, main="Top 10 countries that emitted the most carbon dioxide in 2016 (MT)", cex.main = 0.9, cex.lab = 0.8)
```
### Per Capita CO2 Emissions by Country
```{r}
library(readxl)
library(RColorBrewer)
myPalette <- brewer.pal(5, "Set2")
data <- read_excel('co2 emission per capita 2016.xlsx')
label = paste(data$Country,data$`CO2 emissions (total)`," ")
pie(data$`CO2 emissions (total)`, labels= label, border="white", col=myPalette, main="Top 10 countries that emitted the most carbon dioxide in 2016 per capita (T)", cex.main = 0.9, cex.lab = 0.8)
```