# Sum the financing by themeTheme_GCF_ASEAN <-aggregate(GCF_financing ~ Theme, data = GCF_ASEAN, FUN = sum)# Calculate percentagesTheme_GCF_ASEAN$Percentage <-with(Theme_GCF_ASEAN, GCF_financing /sum(GCF_financing) *100)Theme_GCF_ASEAN
# Sum the financing by themeCountry_GCF_ASEAN <-aggregate(GCF_financing ~ Country, data = GCF_ASEAN, FUN = sum)# Calculate percentagesCountry_GCF_ASEAN$Percentage <-with(Country_GCF_ASEAN, GCF_financing /sum(GCF_financing) *100)Country_GCF_ASEAN
# Create a pie chart using ggplot2ggplot(data = Theme_GCF_ASEAN, aes(x ="", y = GCF_financing, fill = Theme)) +geom_bar(stat ="identity", width =1) +coord_polar(theta ="y") +# Convert bar chart to pie chartgeom_text(aes(label =sprintf("%.1f%%", Percentage)), position =position_stack(vjust =0.5)) +theme_void() +# Remove extra chart elements like axeslabs(fill ="Finance Theme", title ="Distribution of Finance by Theme") +scale_fill_brewer(palette ="Set5") # Use a nice color palette
Warning: Unknown palette: "Set5"
# Create a pie chart using ggplot2ggplot(data = Country_GCF_ASEAN, aes(x ="", y = GCF_financing, fill = Country)) +geom_bar(stat ="identity", width =1) +coord_polar(theta ="y") +# Convert bar chart to pie chartgeom_text(aes(label =sprintf("%.1f%%", Percentage)), position =position_stack(vjust =0.5)) +theme_void() +# Remove extra chart elements like axeslabs(fill ="Finance Theme", title ="Distribution of Finance by Country") +scale_fill_brewer(palette ="Blues") # Use a nice color palette
# Assuming Country_GCF_ASEAN is already loaded and contains columns GCF_financing and Percentage# Reorder the Country factor levels by PercentageCountry_GCF_ASEAN$Country <-factor(Country_GCF_ASEAN$Country, levels = Country_GCF_ASEAN$Country[order(Country_GCF_ASEAN$Percentage, decreasing =FALSE)])# Create a pie chart using ggplot2 with reordered countriesggplot(data = Country_GCF_ASEAN, aes(x ="", y = GCF_financing, fill = Country)) +geom_bar(stat ="identity", width =1) +coord_polar(theta ="y") +# Convert bar chart to pie chartgeom_text(aes(label =sprintf("%.1f%%", Percentage)), position =position_stack(vjust =0.5)) +theme_void() +# Remove extra chart elements like axeslabs(fill ="Country", title ="Distribution of GCF Financing by Country") +scale_fill_brewer(palette ="Blues") # Use a nice color palette
# Load necessary librarieslibrary(dplyr)library(tidyr)# Assume 'data' is your data frame containing the project information# Group the data by 'Countries' and 'Theme', then sum the financing amountsfinancing_by_theme_country <- GCF_ASEAN %>%group_by(Country, Theme) %>%summarise(Total_Financing =sum(GCF_financing, na.rm =TRUE)) %>%pivot_wider(names_from = Theme, values_from = Total_Financing, values_fill =list(Total_Financing =0))
`summarise()` has grouped output by 'Country'. You can override using the
`.groups` argument.
# Print the tableprint(financing_by_theme_country)
# Load necessary librarieslibrary(ggplot2)library(dplyr)library(tidyr)# Assume 'data' is your data frame containing the project information# Prepare the datafinancing_data <- GCF_ASEAN %>%group_by(Country, Theme) %>%summarise(Total_Financing =sum(GCF_financing, na.rm =TRUE)) %>%pivot_wider(names_from = Theme, values_from = Total_Financing, values_fill =list(Total_Financing =0))
`summarise()` has grouped output by 'Country'. You can override using the
`.groups` argument.
# Calculate the proportion of each theme within each countryfinancing_data <- financing_data %>%mutate(Total =`Adaptation`+`Cross-cutting`+`Mitigation`) %>%mutate_at(vars(`Adaptation`, `Cross-cutting`, `Mitigation`), ~ . / Total)# Gather the data for plottingfinancing_data_long <- financing_data %>%pivot_longer(cols =`Adaptation`:`Mitigation`, names_to ="Theme", values_to ="Proportion")# Create a stacked bar chartggplot(financing_data_long, aes(x = Country, y = Proportion, fill = Theme)) +geom_bar(stat ="identity") +labs(title ="Proportion of Financing by Theme for Each Country",y ="Proportion") +theme_minimal() +scale_fill_brewer(palette ="Set5")
# Create a bar chart of GCF Financing by Countryggplot(data = Country_GCF_ASEAN, aes(x = Country, y = GCF_financing, fill = Country)) +geom_bar(stat ="identity", color ="navy") +# Use identity stat for pre-summarized datascale_fill_brewer(palette ="Blues") +# Apply a color palettelabs(title ="GCF Financing by Country", x ="Country", y ="GCF Financing (USD)", fill ="Country") +theme_minimal() +# Apply a minimal themetheme(axis.text.x =element_text(angle =45, hjust =1)) # Rotate x-axis labels for better readability
# Create a bar chart of GCF Financing by Country with values in millions USDggplot(data = Country_GCF_ASEAN, aes(x = Country, y = GCF_financing /1e6, fill = Country)) +geom_bar(stat ="identity", color ="navy") +# Use identity stat for pre-summarized datascale_fill_brewer(palette ="Blues") +# Apply a color palettelabs(title ="GCF Financing by Country", x ="Country", y ="GCF Financing (Million USD)", # Updated labelfill ="Country") +theme_minimal() +# Apply a minimal themetheme(axis.text.x =element_text(angle =45, hjust =1)) # Rotate x-axis labels for better readability