Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@robwschlegel
Created June 20, 2017 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robwschlegel/e89a812ec53bb36f891e86fada847103 to your computer and use it in GitHub Desktop.
Save robwschlegel/e89a812ec53bb36f891e86fada847103 to your computer and use it in GitHub Desktop.
data_gender <- years_of_education[,-5] %>%
left_join(., gender_equality_education[,-5], by = c("ccode", "country.name", "year")) %>%
rename(., education_years = value.x, gender_equality_education = value.y)
data_gender <- data_gender[complete.cases(data_gender$gender_equality_education),]
lm_data_gender1 <- glance(lm(gender_equality_education ~ education_years, data = data_gender))
lm_data_gender2 <- glance(lm(gender_equality_education ~ education_years,
data = filter(data_gender, education_years >= 5)))
# And now for a scatterplot
ggplot(data = data_gender, aes(x = education_years,
y = gender_equality_education)) +
geom_point() +
geom_smooth(colour = "blue", method = "lm") +
geom_smooth(data = filter(data_gender, education_years >= 5), colour = "red", method = "lm") +
geom_label(aes(x = 8.5, y = 0.5, label = paste0("blue line\nR^2 = ",
round(lm_data_gender1$adj.r.squared,3),
"\nred line\nR^2 = ",
round(lm_data_gender2$adj.r.squared,3))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment