Using data from Global Forest Watch, this chart visualizes information of tree cover loss (kha) and forest-related greenhouse gas emissions (mtCO2) from 2001 to 2022.
Sources: Global Forest Watch
# Setwd
setwd("D:/0 - My documents/TOOLS/R/Visual Capitalist/Forest")
# Load data
library(rio)
treecover <- import("D:/0 - My documents/TOOLS/R/Visual Capitalist/Forest/treecover_loss__ha.csv")
library(tidyverse)
library(summarytools)
summary(treecover)
names(treecover) <- c("state","year","loss_ha","c02")
treecover_kha <- treecover %>%
mutate(loss_kha = loss_ha / 1000,
loss_kha = round(loss_kha, 2))
treecover_kha_w <- treecover_kha %>%
select("state", "year","loss_kha") %>%
pivot_wider(
names_from = "state",
values_from = "loss_kha"
)
treecover_kha_w <- treecover_kha_w %>%
mutate(year = as.numeric(year)) %>%
arrange((year))
# Rename
library(janitor)
treecover_kha_w <- treecover_kha_w %>% janitor::clean_names()
names(treecover_kha_w)
treecover_kha_w_chart <- treecover_kha_w %>%
mutate(commodity_driven_deforestation_1 = commodity_driven_deforestation,
urbanization_1 = commodity_driven_deforestation_1 + urbanization,
shifting_agriculture_1 = urbanization_1 + shifting_agriculture,
forestry_1 = shifting_agriculture_1 + forestry,
unknown_1 = forestry_1 + unknown)
summary(treecover_kha_w_chart)# Visualization
library(ggtext)
library(extrafont)
font_import(pattern = "Philosopher")
y
loadfonts()
# List available font families
windowsFonts()
year <- 2019
text <- "In **Vietnam** from **2001** to **2022, 75%** of tree cover loss occurred in areas where the dominant drivers of loss resulted in **deforestation**."
df_text <- data.frame(year = 2019, text = text)
g1 <- ggplot(treecover_kha_w_chart)+
geom_line(aes(x = seq_along(year), y = unknown_1), color = "#483838", linewidth = 2.5)+
geom_area(aes(x = seq_along(year), y = unknown_1), fill = "white", color = NA)+
geom_area(aes(x = seq_along(year), y = forestry_1), fill = "#186F65", color = NA)+
geom_area(aes(x = seq_along(year), y = shifting_agriculture_1), fill = "#B5CB99", color = NA)+
geom_area(aes(x = seq_along(year), y = urbanization_1), fill = "#FCE09B", color = NA)+
geom_area(aes(x = seq_along(year), y = commodity_driven_deforestation_1), fill = "#B2533E", color = NA)+
theme_minimal()+
# Edit background
theme(axis.title = element_blank())+
theme(panel.grid.minor = element_blank())+
theme(panel.grid.major.x = element_blank())+
theme(panel.grid.major.y = element_line(color = "#99BC85", linewidth = 0.1))+
theme(plot.background = element_rect(fill = "#E1F0DA", color = "#E1F0DA")) +
theme(panel.background = element_rect(fill = "#E1F0DA", color = "#E1F0DA"))+
# Scale x.y
scale_x_continuous(breaks = seq(1, 29, by = 1),
expand = c(0, 0),
limits = c(0, 29),
label = c("2001", seq(2, 22, by = 1),"","","","","","",""))+
scale_y_continuous(breaks = seq(0,360, by = 90),
expand = c(0,0),
limits = c(0,380),
label = c("0","90k","180k","270k","360kha"))+
# Add title, sub, caption
labs(title = "Annual Tree Cover Loss\nby Dominant Driver in Vietnam",
subtitle = "Year: 2001 - 2022",
caption = "Sources: Global Forest Watch")+
# Adjust title, sub, caption
theme(plot.title = element_text(size = 18, color = "#186F65",family = "#9Slide03 Philosopher"))+
theme(plot.subtitle = element_text(size = 10, color = "grey30", family = "#9Slide03 Philosopher"))+
theme(plot.caption = element_text(size = 7, color = "grey30"))+
theme(axis.text.y = element_text(size = 9, color = "#186F65",family = "#9Slide03 Philosopher"))+
theme(axis.text.x = element_text(size = 7, color = "#186F65"))+
theme(plot.title.position = "plot")+
# Adjust plot margin
theme(plot.margin = unit(c(0.5, 0.5, 0.1, 0.5), "cm"))+
# ggtext
geom_text(label = "Commodity Driven Deforestation",
colour = "#E1F0DA",
x = 15,
y = 40,
size = 4)+
geom_text(label = "Total",
colour = "#483838",
x = 19,
y = 250,
hjust = 0,
size = 4)+
# Label
geom_label(aes(x = 23, y = 100,
label = "Urbanization"),
stat = "unique",
hjust = 0,
size = 3, fill = "#FCE09B", color = "#186F65")+
geom_label(aes(x = 23, y = 130,
label = "Shifting Agriculture"),
stat = "unique",
hjust = 0,
size = 3, fill = "#B5CB99", color = "#186F65")+
geom_label(aes(x = 23, y = 160,
label = "Forestry"),
stat = "unique",
hjust = 0,
size = 3, fill = "#186F65", color = "#E1F0DA")+
# Add text box
geom_textbox(
data = df_text,
aes(x = 1, y = 350, label = text, box.color = NA),
width = 0.5,
hjust = 0,
vjust = 1,
fill = NA,
color = "#483838",
size = 3.5)
# Save chart
ggsave("forest.png", width = 6.5, height = 5,dpi = 300,units = c("in"))