---
title: "ANLY 512: Lab 2"
author: "Janvich Vanichpipat"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source_code: embed
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(scales)
library(R.utils)
library(ncdf4)
library(data.table)
library(lubridate)
library(ggridges)
library(shadowtext)
library(viridis)
```
Question 1
=======================================================================
Inputs {.sidebar}
-----------------------------------------------------------------------
#### <b>Question 1</b>
What has happened to the global temperature over its history?
Figure 1.1 shows the changes in global surface temperature compared to the long-term average from 1951 to 1980. As we can see, earth's global average surface temperature in 2020 tied with 2016 as the hottest year on record.
Figure 1.2 shows the ridge line plot of land temperature that changed and moved over time. These are the important climate change warning figures that I want to present in this dashboard. It clearly illustrates what was happened to the global temperature over its history compared to the statistical parameter.
Temperature Anomaly (C) means a departure from a reference value or long-term average.A positive anomaly indicates that the observed temperature was warmer than the reference value, while a negative anomaly indicates that the observed temperature was cooler than the reference value. Credit: NCEI
Column {data-height=650 .tabset .tabset-fade}
-----------------------------------------------------------------------
### Figure 1.1
```{r}
GT <- read.table("https://data.giss.nasa.gov/gistemp/graphs/graph_data/Global_Mean_Estimates_based_on_Land_and_Ocean_Data/graph.txt", header = FALSE, col.names = c("Year", "No_Smoothing", "Lowess(5)"), skip = 5)
ggplot(data = GT, aes(x = Year, y = No_Smoothing)) +
geom_line(aes(color = "1"), size = 0.4) +
geom_point(fill = "white", aes(color = "1"), shape = 21, show.legend = FALSE) +
geom_smooth(se = FALSE, aes(color = "2"), size = 0.5, span = 0.15) +
scale_x_continuous(breaks = seq(1880, 2023, 20), expand = c(0,0)) +
scale_y_continuous(limits = c(-0.5,1.5), expand = c(0,0)) +
scale_color_manual(name = NULL,
breaks = c(1,2),
values = c("gray","black"),
labels = c("Annual mean", "Lowess smoothing")) +
labs(
x = "YEAR",
y = "Temperature Anomaly (C)",
title = "GLOBAL LAND-OCEAN TEMPERATURE INDEX",
subtitle = "Data source: NASA's Goddard Institute for Space Studies (GISS).\nCredit: NASA/GISS") +
theme_light() +
theme(
axis.ticks = element_blank(),
axis.text = element_text(size = 6),
axis.title = element_text(size = 6),
plot.title = element_text(size = 10, color = "blue", face = "bold"),
plot.subtitle = element_text(size = 6),
legend.position = c(0.15, 0.9),
legend.text = element_text(size = 6),
legend.key.height = unit(10, "pt"),
legend.margin = margin(1,1,1))
```
### Figure 1.2
```{r}
#url <- "https://data.giss.nasa.gov/pub/gistemp/gistemp250_GHCNv4.nc.gz"
#download.file(url, destfile = "gistemp250_GHCNv4.nc.gz")
#gunzip("gistemp250_GHCNv4.nc.gz")
nc_data <- nc_open('gistemp250_GHCNv4.nc')
{
sink('gistemp250_GHCNv4.txt')
print(nc_data)
sink()
}
lon <- ncvar_get(nc_data, "lon")
lat <- ncvar_get(nc_data, "lat", verbose = F)
t <- ncvar_get(nc_data, "time")
t_anomaly.array <- ncvar_get(nc_data, "tempanomaly")
fillvalue <- ncatt_get(nc_data, "tempanomaly", "_FillValue")
t_anomaly.array[t_anomaly.array == fillvalue$value] <- NA
t_data <- as.data.table(t_anomaly.array) %>%
as_tibble() %>%
select(longitude = V1, latitude = V2, time = V3, t_diff = value) %>%
mutate(longitude = lon[longitude],
latitude = lat[latitude],
time = t[time] + as.Date("1800-01-01"),
year = year(time)) %>%
group_by(year, longitude, latitude) %>%
summarize(t_diff = mean(t_diff), .groups = "drop") %>%
filter(year >= 1950 & year < 2022) %>%
group_by(year) %>%
mutate(t_ave = mean(t_diff))
t_data %>%
ggplot(aes(x = t_diff,
y = factor(year, levels = seq(2021, 1950, -1)),
fill = t_ave)) +
geom_density_ridges(bandwidth = 0.3, scale = 3,
size = 0.2, color="white") +
scale_fill_gradient2(low = "darkblue", mid = "white", high = "darkred",
midpoint = 0, guide = "none") +
coord_cartesian(xlim=c(-5, 5)) +
scale_x_continuous(breaks = seq(-4, 4, 2)) +
scale_y_discrete(breaks = seq(1950, 2020, 10)) +
labs(y = NULL,
x = "Temperature Anomaly (\u00B0 C)",
title = "LAND TEMPERATURE ANORMALY DISTRIBUTION",
subtitle = "Data source: NASA's Goddard Institute for Space Studies (GISS).\nCredit: NASA/GISS") +
theme(
axis.ticks = element_blank(),
axis.text = element_text(size = 6),
axis.title = element_text(size = 6),
plot.title = element_text(size = 10, color = "blue", face = "bold"),
plot.subtitle = element_text(size = 6),
panel.background = element_rect(fill = "black"),
panel.grid = element_blank())
```
Question 2
=======================================================================
Inputs {.sidebar}
-----------------------------------------------------------------------
#### <b>Question 2</b>
How much has global temperature increased since 1880?
Figure 2 visualizes the global average temperature from 1880 to 2021 in the bar chart plot. As we can see, the global average temperature in 2021 is estimated to be about 1.02 C above the 1880 average, and it most likely to continue increasing in the future. This graph is important for showing the global average temperature trend.
Column
-----------------------------------------------------------------------
### Figure 2
```{r}
DF <- read_csv("GLB.Ts+dSST.csv", skip = 1, na = "***") %>%
select(year = Year, t_diff = `J-D`) %>%
drop_na()
DF %>%
ggplot(aes(x = year, y = t_diff, fill = t_diff)) +
geom_col(show.legend = FALSE) +
scale_x_continuous(breaks = seq(1880, 2023, 20), expand = c(0,0)) +
scale_y_continuous(limits = c(-0.5,1.25), expand = c(0,0)) +
scale_fill_stepsn(colors = c("blue", "white", "red"),
values = rescale(c(min(DF$t_diff), 0, max(DF$t_diff))),
limit = c(min(DF$t_diff), max(DF$t_diff)),
n.break = 9) +
labs(
x = "YEAR",
y = "Global Temperature (C)",
title = "GLOBAL AVERAGE TEMPERATURE (1880-2021)",
subtitle = "Data source: NASA's Goddard Institute for Space Studies (GISS).\nCredit: NASA/GISS") +
theme_light() +
theme(
axis.ticks = element_blank(),
axis.text = element_text(size = 6),
axis.title = element_text(size = 6),
plot.title = element_text(size = 10, color = "blue", face = "bold"),
plot.subtitle = element_text(size = 6),
panel.background = element_rect(fill = "black", color = "black")
)
#max_t_diff <- round(max(DF$t_diff), 2)
```
Question 3
=======================================================================
Inputs {.sidebar}
-----------------------------------------------------------------------
#### <b>Question 3</b>
What is the trend in the global Carbon Dioxide emission?
Carbon Dioxide (CO2) is one of the major causes of global warming as it is greenhouse gas that build up in the atmosphere and warm the climate, leading to many other changes in land and ocean temperature that already discussed in previous questions.
Figure 3 shows the atmospheric Carbon Dioxide trend from 1959 to 2021. As we can see the amount of annual mean CO2 emission continuing increasing every year. The amount of annual mean CO2 emission on 2021 was increased from 1959 over 30%.
Column
-----------------------------------------------------------------------
### Figure 3
```{r}
CO <- read_csv("co2_annmean_mlo.csv")
ggplot(data = CO, aes(x = year, y = mean)) +
geom_line(stat='identity', color = "blue") +
geom_point(shape=23, fill="white", color = "blue", size=1) +
geom_smooth(method = lm, color = "#0099FF", linetype = "longdash", size = 0.5) +
scale_x_continuous(breaks = seq(1959, 2021, 10), expand = c(0,0)) +
scale_y_continuous(limits = c(300,425), expand = c(0,0)) +
labs(
x = "YEAR",
y = "Annual Mean CO2 Emission (ppm)",
title = "TREND IN ATMOSPHERIC CARBON DIOXIDE (1959-2021)",
subtitle = "Data source: Global Monitoring Laboratory. \nCredit: GML/NOAA") +
theme_light() +
theme(
axis.ticks = element_blank(),
axis.text = element_text(size = 6),
axis.title = element_text(size = 6),
plot.title = element_text(size = 10, color = "blue", face = "bold"),
#panel.background = element_rect(fill = "#CCCCCC"),
plot.subtitle = element_text(size = 6))
```
Question 4
=======================================================================
Inputs {.sidebar}
-----------------------------------------------------------------------
#### <b>Question 4</b>
What are energy related Greenhouse gas emission?
The energy shows in Figure 4 are related to the Greenhouse gas emission. As we can see, all value is increasing over the year from 2000. These energy created large amount of CO2 into the air that trap heat in atmosphere leading to global warming.
The main energy related Greenhouse gas emission from this figure is the CO2 from flaring. Flaring is the process of burning excess natural gas at the production well using a dedicated flare to ignite the methane and other components in the gas, which can result in both methane and carbon dioxide emissions (CO2)
According to the World Bank, assuming a 'typical' associated gas composition, a flare combustion efficiency of 98% and a Global Warming Potential for methane of 25, each cubic meter of associated gas flared results in about 2.8 kilograms of CO2 equivalent emissions, resulting in over 400 million tons of CO2 equivalent emissions annually.
Column
-----------------------------------------------------------------------
### Figure 4
```{r}
EG <- read.csv("energy-related-greenhouse-gas-emissions-2000-2021r.csv")
#EG %>% group_by(ET)
ggplot(EG, aes(x=Year, y=Value, fill=ET)) +
geom_area(stat = 'identity', position = 'stack',
alpha = 0.6, size=0.2, color="white") +
scale_fill_viridis(option = "C", discrete = T, name = NULL) +
scale_x_continuous(breaks = seq(2000, 2021, 2), expand = c(0,0)) +
scale_y_continuous(limits = c(0,45), expand = c(0,0)) +
labs(
x = "YEAR",
y = "Global GHG emissions (GtCO2eq)",
title = "ENERGY RELATED GREENHOUSE GAS EMISSION (2000-2021)",
subtitle = "Data source: International Energy Agency Organization. \nCredit: IEA") +
theme_light() +
theme(
axis.ticks = element_blank(),
axis.text = element_text(size = 6),
axis.title = element_text(size = 6),
plot.title = element_text(size = 10, color = "blue", face = "bold"),
legend.title = element_text(size = 6),
legend.text = element_text(size = 6),
plot.subtitle = element_text(size = 6))
```