--- title: "GCT_subnational_2023" author: "Jia-Shen" date: "2023-08-04" output: html_document --- ```{r library} rm(list = ls()) library(dplyr) library(tidyr) library(ggplot2) library(countrycode) ``` ```{r data observation} ta2022 <- read.csv('target_actor2022.csv') ta2023 <- read.csv('target_actor2023.csv') str(ta2022) unique(ta2022$target_year) unique(ta2023$target_year) head(ta2022) head(ta2023) ``` ```{r subsetting subtracting data with target year too old} ta2022_n <- ta2022 %>% subset(target_year >= 2022) ta2023_n <- ta2023 %>% subset(target_year >= 2023) ``` ```{r summarize df} sum2022 <- ta2022_n %>% group_by(iso) %>% summarise('2022 target' = length(iso)) sum2023 <- ta2023_n %>% group_by(iso) %>% summarise('2023 target' = length(iso)) df.comp <- full_join(sum2022, sum2023, by = 'iso') df.comp$country <- countrycode(df.comp$iso, origin = 'iso3c', destination = 'country.name') df.comp write.csv(df.comp, file = "target_comparison") ``` ```{r plotting df} sum2022.long <- ta2022_n %>% group_by(iso) %>% summarise('target_amount' = length(iso), year = '2022') sum2023.long <- ta2023_n %>% group_by(iso) %>% summarise('target_amount' = length(iso), year = '2023') df.comp.long <- bind_rows(sum2022.long, sum2023.long) df.comp.long ``` ```{r dodging bar chart} ggplot(df.comp.long, aes(x = reorder(iso, target_amount), y = target_amount, fill = as.factor(year))) + geom_bar(stat = "identity", position = "dodge") + labs(title = "Climate Target Amounts in 2022 and 2023", x = "Country (ISO)", y = "Target Amount") + scale_fill_discrete(name = "Year", labels = c("2022", "2023")) ``` ![](https://hackmd.io/_uploads/HJTHSR9o2.png) ```{r} ggplot(df.comp.long, aes(x = reorder(iso, target_amount), y = target_amount, fill = as.factor(year))) + geom_bar(stat = "identity", position = "dodge") + labs(title = "Climate Target Amounts in 2022 and 2023", x = "Country (ISO)", y = "Target Amount") + scale_fill_discrete(name = "Year", labels = c("2022", "2023")) + scale_y_sqrt() ``` ![](https://hackmd.io/_uploads/SkMFrR5sh.png) # New dataset taken the 2023 dataset data loss into account ```{r compare the dataset} ta_int <- semi_join(ta2023_n, ta2022_n, by = 'target_id') ta_int ta_ant <- anti_join(ta2022_n, ta2023_n, by = 'target_id') ta_ant_city <- anti_join(ta2023_nn,ta2022_n, by = 'actor_id') length(unique(ta_ant_city$actor_id)) ``` There are only 1174 rows of data intersecting between the two, which doesn't make sense, since most of the target are not expired. The following analysis put the data back to 2023. BTW, there are 922 new actors in 2023. ```{r} ta2023_nn <- bind_rows(ta2023_n, ta_ant) ta2023_nn ``` ```{r summarize ndf} sum2023_n <- ta2023_nn %>% group_by(iso) %>% summarise('2023 target' = length(iso)) df.comp.n <- full_join(sum2022, sum2023_n, by = 'iso') df.comp.n$country <- countrycode(df.comp.n$iso, origin = 'iso3c', destination = 'country.name') df.comp.n write.csv(df.comp.n, file = "target_comparison_n") ``` ```{r plotting ndf} sum2023.n.long <- ta2023_nn %>% group_by(iso) %>% summarise('target_amount' = length(iso), year = '2023') df.comp.n.long <- bind_rows(sum2022.long, sum2023.n.long) ``` ```{r n dodging bar chart} ggplot(df.comp.n.long, aes(x = reorder(iso, target_amount), y = target_amount, fill = as.factor(year))) + geom_bar(stat = "identity", position = "dodge") + labs(title = "Climate Target Amounts in 2022 and 2023", x = "Country (ISO)", y = "Target Amount") + scale_fill_discrete(name = "Year", labels = c("2022", "2023")) ``` ![](https://hackmd.io/_uploads/Hk74thTo3.png) ```{r} ggplot(df.comp.n.long, aes(x = reorder(iso, target_amount), y = target_amount, fill = as.factor(year))) + geom_bar(stat = "identity", position = "dodge") + labs(title = "Climate Target Amounts in 2022 and 2023", x = "Country (ISO)", y = "Target Amount") + scale_fill_discrete(name = "Year", labels = c("2022", "2023")) + scale_y_sqrt() ``` ![](https://hackmd.io/_uploads/SJxwYhTon.png) ## new comparison ```{r South Aftica} ZAF2022 <- ta2022_n[ta2022_n$iso == 'ZAF',] ZAF2023 <- ta2023_nn[ta2023_nn$iso == 'ZAF',] ZAF2023.s <- anti_join(ZAF2023,ZAF2022, by = 'target_id') ZAF2023_cities <- unique(ZAF2023.s$name) paste(ZAF2023_cities, collapse = ', ') ``` ```{r UK} GBR2022 <- ta2022_n[ta2022_n$iso == 'GBR',] GBR2023 <- ta2023_nn[ta2023_nn$iso == 'GBR',] GBR2023.s <- anti_join(GBR2023, GBR2022, by = 'target_id') paste(unique(GBR2023.s$name), collapse = ', ') ``` ```{r USA} USA2022 <- ta2022_n[ta2022_n$iso == 'USA',] USA2023 <- ta2023_nn[ta2023_nn$iso == 'USA',] USA2023.s <- anti_join(USA2023, USA2022, by = 'target_id') paste(unique(USA2023.s$name), collapse = ', ') USA2023.s[c('City', 'State')] <- str_split_fixed(USA2023.s$name, ',', 2) ggplot(data = USA2023.s, aes(x = State)) + geom_bar() + scale_x_discrete(guide = guide_axis(n.dodge = 2)) ``` ```{r Austria} AUT2022 <- ta2022_n[ta2022_n$iso == 'AUT',] AUT2023 <- ta2023_nn[ta2023_nn$iso == 'AUT',] AUT2023.s <- anti_join(AUT2023, AUT2022, by = 'target_id') paste(unique(AUT2023.s$name), collapse = ', ') ``` ```{r Belgium} BEL2022 <- ta2022_n[ta2022_n$iso == 'BEL',] BEL2023 <- ta2023_nn[ta2023_nn$iso == 'BEL',] BEL2023.s <- anti_join(BEL2023, BEL2022, by = "actor_id") BEL2023.s paste(unique(BEL2023.s$name), collapse = ', ') ``` ```{r Bulgaria} BGR2022 <- ta2022_n[ta2022_n$iso == 'BGR',] BGR2023 <- ta2023_nn[ta2023_nn$iso == 'BGR',] BGR2023.s <- anti_join(BGR2023, BGR2022, by = 'actor_id') paste(unique(BGR2023.s$name), collapse = ', ') ``` ```{r Croatia} HRV2022 <- ta2022_n[ta2022_n$iso == 'HRV',] HRV2023 <- ta2023_nn[ta2023_nn$iso == 'HRV',] HRV2023.s <- anti_join(HRV2023, HRV2022, by = "actor_id") paste(unique(HRV2023.s$name), collapse = ', ') ``` ```{r Denmark} DNK2022 <- ta2022_n[ta2022_n$iso == 'DNK',] DNK2023 <- ta2023_nn[ta2023_nn$iso == 'DNK',] DNK2023.s <- anti_join(DNK2023, DNK2022, by = "actor_id") paste(unique(DNK2023.s$name), collapse = ', ') ``` ```{r Estonia} EST2022 <- ta2022_n[ta2022_n$iso == 'EST',] EST2023 <- ta2023_nn[ta2023_nn$iso == 'EST',] EST2023.s <- anti_join(EST2023, EST2022, by = "actor_id") paste(unique(EST2023.s$name), collapse = ', ') ``` ```{r Finland} FIN2022 <- ta2022_n[ta2022_n$iso == 'FIN',] FIN2023 <- ta2023_nn[ta2023_nn$iso == 'FIN',] FIN2023.s <- anti_join(FIN2023, FIN2022, by = "actor_id") paste(unique(FIN2023.s$name), collapse = ', ') ``` ```{r France} FRA2022 <- ta2022_n[ta2022_n$iso == 'FRA',] FRA2023 <- ta2023_nn[ta2023_nn$iso == 'FRA',] FRA2023.s <- anti_join(FRA2023, FRA2022, by = "actor_id") paste(unique(FRA2023.s$name), collapse = ', ') ```