Skip to content

Instantly share code, notes, and snippets.

@trinker
Created April 13, 2015 18:45
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 trinker/1626def312385c81dfa6 to your computer and use it in GitHub Desktop.
Save trinker/1626def312385c81dfa6 to your computer and use it in GitHub Desktop.
Slopegraph: ggplot2
if (!require("pacman")) install.packages("pacman"); library(pacman)
p_load(dplyr, qdap, qdapRegex, qdapDictionaries, ggplot2, scales)
nms <- unlist(qdapRegex::TC(sample(NAMES[[1]], 26)))
dat <- data_frame(
year = rep(1997:2000, each = length(nms)),
observation = rep(nms, length(1997:2000)),
score = sample(50:100, length(nms)*length(1997:2000), TRUE)
)
ggplot(dat, aes(x=year, y=score, color=observation, group = observation)) +
geom_line(alpha=.5, size=.6, show_guide=FALSE) +
theme_bw() +
theme(
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
axis.ticks.x = element_blank(),
axis.text.x = element_text(size=14),
panel.border = element_blank()
) +
geom_text(size=3, aes(label = observation), show_guide=FALSE) +
coord_cartesian(ylim=c(50, 102), xlim=c(1996.5, 2000.5)) +
scale_x_continuous(breaks=c(1997:2000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment