library(tidyverse)
library(plotly)
library(scales)
# 1. Load and clean data
wdi_raw <- read_csv("C:/Users/yudit/Downloads/wdi_parl.csv")
wdi_clean <- wdi_raw %>%
filter(region != "Aggregates", year == 2019) %>%
drop_na(SG.GEN.PARL.ZS, NY.GDP.PCAP.KD) %>%
rename(prop_women = SG.GEN.PARL.ZS,
gdp_cap = NY.GDP.PCAP.KD)
# Load data here
wdi_raw <- read_csv("C:/Users/yudit/Downloads/wdi_parl.csv")
Do the following:
geom_point()). # 1. Compare 2000 vs 2020 for a
subset of countries > progress_data <-
read_csv(“C:/Users/yudit/Downloads/wdi_parl.csv”) %>%filter(year %in% c(2000, 2020), country %in% c("Rwanda", "United Arab Emirates", "United States", "Mexico", "Spain", "Ethiopia")) %>%select(country, year, SG.GEN.PARL.ZS) %>%pivot_wider(names_from = year, names_prefix = "yr", values_from = SG.GEN.PARL.ZS)ggplotly(). # 2. Create
the plot > p_progress <- ggplot(progress_data) +geom_segment(aes(x = yr2000, xend = yr2020, y = country, yend = country), color = "grey") +geom_point(aes(x = yr2000, y = country), color = "red", size = 3) +geom_point(aes(x = yr2020, y = country), color = "blue", size = 3) +theme_minimal() +labs(title = "Progress: 2000 (Red) vs 2020 (Blue)", x = "% Women in Parliament", y = NULL)Make sure the hovering tooltip is more informative than the default.
Prepare data using 2019 instead of 2020 > progress_data <- read_csv(“C:/Users/yudit/Downloads/wdi_parl.csv”) %>%
# Filter for 2019 (the last year in your dataset)filter(year %in% c(2000, 2019), country %in% c("Rwanda", "United Arab Emirates", "United States", "Mexico", "Spain", "Ethiopia")) %>%select(country, year, SG.GEN.PARL.ZS) %>%# This creates 'yr2000' and 'yr2019' columnspivot_wider(names_from = year, names_prefix = "yr", values_from = SG.GEN.PARL.ZS)Good luck and have fun!