Guest User

Untitled

a guest
Nov 17th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. library(tidyverse)
  2. library(lubridate) # just in case I need to manipulate a date
  3. library(stringr) # just in case I need to manipulated a string
  4. library(stevemisc) # for my personal theme
  5. library(scales) # just in case I need to fudge a y-axis to be a scale
  6. library(knitr) # just in case I need a markdown table
  7.  
  8. # I'm going to assume you have Fariss' data downloaded somewhere. Here's what mine looks like.
  9. LHR <- read_csv("~/Dropbox/data/latent-human-rights/HumanRightsProtectionScores_v2.04.csv")
  10.  
  11. LHR %>%
  12. filter(COW == 2 | COW == 710) %>%
  13. mutate(Country = ifelse(COW == 2, "United States", "China"),
  14. lwr = NA) %>%
  15. ggplot(.,aes(YEAR, latentmean, group = Country, color=Country,
  16. ymin = latentmean - 1.96*latentsd, ymax = latentmean + 1.96*latentsd)) +
  17. theme_steve() + theme(legend.position="bottom") +
  18. geom_ribbon(aes(fill = Country), alpha = I(0.2), color = "black") + geom_line() +
  19. ylab("Mean Latent Human Rights Protection") + xlab("Year") +
  20. scale_x_continuous(breaks = seq(1950, 2015, by = 5)) +
  21. labs(title = "Human Rights Protection Scores for the U.S. and China, 1949-2013",
  22. subtitle = "We oberve a clear contrast between the two starting in 1965 but observe the United States' downward trend.",
  23. caption = "Data: Fariss' Latent Human Rights Protection Scores (v. 2.04)")
  24.  
  25. LHR %>%
  26. filter(COW == 2 | COW == 20 | COW == 70) %>%
  27. mutate(Country = ifelse(COW == 2, "United States", NA),
  28. Country = ifelse(COW == 20, "Canada", Country),
  29. Country = ifelse(COW == 70, "Mexico", Country),
  30. lwr = NA) %>%
  31. ggplot(.,aes(YEAR, latentmean, group = Country, color=Country,
  32. ymin = latentmean - 1.96*latentsd, ymax = latentmean + 1.96*latentsd)) +
  33. theme_steve() + theme(legend.position="bottom") +
  34. geom_ribbon(aes(fill = Country), alpha = I(0.2), color = "black") + geom_line() +
  35. ylab("Mean Latent Human Rights Protection") + xlab("Year") +
  36. scale_x_continuous(breaks = seq(1950, 2015, by = 5)) +
  37. labs(title = "Human Rights Protection Scores for the U.S., Canada, and Mexico, 1949-2013",
  38. subtitle = "Notice the U.S. is not exactly a world leader in human rights protections despite demonstrations to the contrary.",
  39. caption = "Data: Fariss' Latent Human Rights Protection Scores (v. 2.04)")
Add Comment
Please, Sign In to add comment