Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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