Skip to content

Instantly share code, notes, and snippets.

@JonasMoss
Created January 4, 2018 14:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save JonasMoss/66b0f973cb996779cfab671fa7ac18fe to your computer and use it in GitHub Desktop.
## Makes a plot checking for clear associations between politics and postign in SSC.
## Data from: http://slatestarcodex.com/Stuff/ssc2018public.xlsx
library("tidyverse")
SSC = read_excel("ssc2018public.xlsx") # Downloaded from SSC.
Politics = as.factor(SSC$PoliticalAffiliation)
Comments = as.factor(SSC$Comment)
## Not everyone will agree with my classification.
## Check out the content of lev if you're worried.
lev = levels(Politics)
levels(Politics) = list("Conservative" = c(lev[1],lev[4],lev[15],lev[17],lev[18],lev[22]),
"Libertarian" = c(lev[2],lev[3],lev[5],lev[6],lev[7],lev[10],lev[12],lev[13],lev[20],lev[21]),
"Social democratic" = c(lev[19]),
"Liberal" = c(lev[8],lev[9],lev[16]),
"Socialist" = c(lev[11],lev[14]))
## I change the comments classification from categorical to numerical.
levy = levels(Comments)
levels(Comments) = list("0" = levy[4],
"1" = levy[3],
"2" = levy[1],
"3" = levy[2],
"4" = levy[5])
Comments = as.numeric(Comments)
levy = c(1:5, NA)
## Now I do the final manipulations before plotting.
tib = tibble(Comments = Comments, Politics = Politics)
count(tib, Politics, Comments) -> counts
lev = levels(Politics)
# Somewhat appropriate colours. Make the graph hard to read though.
cols = c("blue4", "purple", "red", "blue", "red4")
## Plotting time!
plot(c(1,5), c(0,0.81), type = "n", bty = "l",
xlab = "Posting frequency", ylab = "Proportion")
i = 1
for(name in lev) {
subtable = filter(counts, Politics == name)
lines(subtable$Comments, subtable$n/sum(subtable$n), type = "b", col = cols[i], pch = 20)
i = i + 1
}
legend("topright", lev, col = cols, bty = "n", lty = 1, pch = 20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment