Skip to content

Instantly share code, notes, and snippets.

@apreshill
Last active February 25, 2019 03:04
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 apreshill/7a9d6f4fd251551530278332a4d0ff2f to your computer and use it in GitHub Desktop.
Save apreshill/7a9d6f4fd251551530278332a4d0ff2f to your computer and use it in GitHub Desktop.
library(tidyverse)
set.seed(1000)
asdpop_base <- tibble::tibble(
time1 = sample(1:100, 100, replace = F),
time2 = time1) %>%
tidyr::gather(x, y, time1:time2, factor_key = TRUE)
asdpop <- asdpop_base %>%
mutate(services = as.factor(case_when(
x == "time1" & y <= 30 ~ 1,
x == "time1" & y > 30 ~ 0,
x == "time2" & y <= 60 ~ 1,
TRUE ~ 0
)))
asdpop
library(ggrepel)
pos <- position_jitter(width = .25,
height = 0,
seed = 2018)
# trying out direct labels
# need to use full dataset (not filtered) b/c of matching up with jittered points
labels <- asdpop %>%
mutate(callout = as.factor(if_else(y %in% c(20, 77), 1, 0)))
dotleg <- ggplot(labels, aes(x, y))
dotleg <- dotleg + geom_jitter(aes(colour = services),
position = pos,
alpha = .75, size = 2)
dotdirect <- dotleg +
guides(colour = FALSE) +
# add the black outlines- transparent for callout = 0
geom_jitter(aes(alpha = callout),
colour = "black",
size = 3, shape = 1,
position = pos) +
scale_alpha_manual(values = c(0, 1), guide = 'none') +
# add the labels- transparent for callout = 0
geom_label_repel(aes(alpha = callout, label = services),
position = pos)
dotdirect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment