final project

Author

Shiya Huang

Published

March 27, 2024

1 - Initial Data Result

options(repos = c(CRAN = "https://cran.rstudio.com/"))

#| message: false
#| warning: false

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.0     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(readxl)
library(sf)
Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(leaflet)
library(plotly)

Attaching package: 'plotly'

The following object is masked from 'package:ggplot2':

    last_plot

The following object is masked from 'package:stats':

    filter

The following object is masked from 'package:graphics':

    layout
fund <- read_excel("Green Climate Fund.xlsx")
world <- read_sf("custom.geo.json")


size_colors <- c("#fffcd3", "#fdde92", "#fea26c", "#e94e54", "gray")
size_levels <- c("Micro", "Small", "Medium", "Large", "NA")

new <- fund %>%
  filter(!str_detect(Countries, ",")) %>%
  rename(region = Countries, size = `Project Size`) %>%
  group_by(region, size) %>%
  filter(row_number() == 1) %>%
  select(region, size) %>%
  group_by(region) %>%
  filter(row_number() == 1) %>%
  mutate_at("size", ~factor(., levels = size_levels[1:4], ordered = T))


pal <- colorFactor(size_colors[1:4], levels = size_levels[1:4])

world %>%
  left_join(new %>% rename(name = region)) %>%
  leaflet() %>%
  setView(0,0,zoom = 1.5) %>%
  addPolygons(label = ~name, weight = 1,
              color = "white", fillColor = ~pal(size), 
              fillOpacity = 1) %>%
  addLegend(color = size_colors, title = "Project Size",
            opacity = 1, labels = size_levels,
            position = "bottomright")
Joining with `by = join_by(name)`

2

install.packages("reshape2")

The downloaded binary packages are in
    /var/folders/cp/x4c86z354zq1gfn38__r36tc0000gn/T//Rtmp3dNPSd/downloaded_packages
library(reshape2)

Attaching package: 'reshape2'
The following object is masked from 'package:tidyr':

    smiths
df <- data.frame(indicator = c("Adaptation", "Mitigation", "Dual benefits"),
                `2019` = c(42L, 282L, 14L),
                `2020` = c(55L, 261L, 16L),
                `2021` = c(54L, 453L, 42L),
                `2022` = c(70L, 619L, 41L))

rownames(df) <- c("Adaptation", "Mitigation", "Dual benefits")
new <- reshape2::melt(df, id.vars = 1, variable.name = "year")
new$year <- as.numeric(gsub("X", "", new$year))
new
       indicator year value
1     Adaptation 2019    42
2     Mitigation 2019   282
3  Dual benefits 2019    14
4     Adaptation 2020    55
5     Mitigation 2020   261
6  Dual benefits 2020    16
7     Adaptation 2021    54
8     Mitigation 2021   453
9  Dual benefits 2021    42
10    Adaptation 2022    70
11    Mitigation 2022   619
12 Dual benefits 2022    41
plot_ly(data = new, x = ~year, y = ~value, color = ~indicator, type = 'scatter',
        mode = "lines") %>%
  layout(title = "Global Public Climate Finance by Adaption/Mitigation")
plot_ly(data = new, x = ~year, y = ~value,type = "bar" ,color = ~indicator) %>%
  layout(title = "Global Public Climate Finance by Adaption/Mitigation")

3

CO2 <- read_excel("EDGARv8.0_FT2022_GHG_booklet_2023_fossilCO2_only.xlsx", 
                  sheet = "fossil_CO2_totals_by_country")%>%
  select(Country, `2022`)

funds <- read_excel("CFU-Website-MASTER-February-2024.xlsx", sheet = "Pledges")
combined_data <- funds %>%
  select(Country, `Country Income Level`, `Deposited (USD million current)`) %>%
  group_by(Country, `Country Income Level`) %>%
  filter(row_number() == 1) %>%
  left_join(CO2) %>%
  rename(value = `2022`) %>%
  mutate_at("Country Income Level", ~factor(., levels = c("Not applicable", "Lower middle income", "Upper middle income", "High income"), ordered = T))
Joining with `by = join_by(Country)`
combined_data
# A tibble: 68 × 4
# Groups:   Country, Country Income Level [68]
   Country        `Country Income Level` `Deposited (USD million current)` value
   <chr>          <ord>                                              <dbl> <dbl>
 1 Belgium        High income                                         7.86  90.4
 2 Canada         High income                                        19.9  582. 
 3 Finland        High income                                         6.83  37.3
 4 France         High income                                         0.67  NA  
 5 Korea, Rep.    High income                                         3     NA  
 6 Netherlands    High income                                        48.6  135. 
 7 Norway         High income                                        18.8   42.3
 8 Sweden         High income                                        10.4   37.9
 9 Switzerland    High income                                        11.0   NA  
10 United Kingdom High income                                       203.   341. 
# ℹ 58 more rows
plot_ly(data = combined_data, x = ~value, 
        y = ~`Deposited (USD million current)`, 
        mode = "markers",
        type = "scatter",
        marker = list(size = ~value/20,opacity = 0.4), 
        color = ~`Country Income Level`,
        colors = c("skyblue","green", "red"),
        hovertemplate = ~paste0("Country:", Country, "\n","Total CO2 Fossil Fuel Emission:", round(value), 
                                "\n", "Total Climate Fund Deposited (USD million current):", 
                                `Deposited (USD million current)`)) %>%
  layout(title = "climate fund is going to xxxxx",
         legend = list(title = list(text = "Income Group")),
       yaxis = list(title = "Total Climate Fund Deposited (USD million current)",type = "log"),
       xaxis = list(title = "Total CO2 Fossil Fuel Emission", type = "log"))
Warning: Ignoring 24 observations
CO2 <- read_excel("EDGARv8.0_FT2022_GHG_booklet_2023_fossilCO2_only.xlsx", 
                  sheet = "fossil_CO2_totals_by_country")%>%
  select(Country, `2022`)

funds <- read_excel("CFU-Website-MASTER-February-2024.xlsx", sheet = "Pledges")
combined_data <- funds %>%
  select(Country, `Country Income Level`, `Deposited (USD million current)`) %>%
  group_by(Country, `Country Income Level`) %>%
  filter(row_number() == 1) %>%
  left_join(CO2) %>%
  rename(value = `2022`) %>%
  mutate_at("Country Income Level", ~factor(., levels = c("Not applicable", "Lower middle income", "Upper middle income", "High income"), ordered = T))
Joining with `by = join_by(Country)`
plot_ly(data = combined_data, x = ~value, mode = "markers",
        y = ~`Deposited (USD million current)`, size = 10, opacity = 0.5,
        hovertemplate = ~paste0("Country:", Country, "\n","Total CO2 Fossil Fuel Emission:", round(value), 
                                "\n", "Total Climate Fund Deposited (USD million current):", 
                                `Deposited (USD million current)`),
        type = "scatter" ,color = ~`Country Income Level`) %>%
  layout(title = "climate fund is going to xxxxx",
       yaxis = list(title = "Total Climate Fund Deposited (USD million current)"),
       xaxis = list(title = "Total CO2 Fossil Fuel Emission"))
Warning: Ignoring 24 observations