Skip to content

Instantly share code, notes, and snippets.

@mjskay
Last active November 15, 2019 23:42
Show Gist options
  • Select an option

  • Save mjskay/8ecc1c58cb72b36cb4888257b8b00ddf to your computer and use it in GitHub Desktop.

Select an option

Save mjskay/8ecc1c58cb72b36cb4888257b8b00ddf to your computer and use it in GitHub Desktop.
Blinky quantile dotplot + hypothetical outcome plot
library(tidyverse)
library(gganimate)
library(tidybayes) # need latest vesion from github for geom_dotsh()
k = 50
draws = tibble(
x = qnorm(ppoints(k)),
draw = sample(1:k, k)
)
p = tibble(
frame = 1:k,
draws = list(draws)
) %>%
unnest(draws) %>%
ggplot(aes(x = x, y = 0)) +
geom_dotsh(aes(fill = draw == frame, group = frame), shape = 21, orientation = "horizontal") +
guides(fill = FALSE) +
scale_fill_manual(values = c("gray75", "red")) +
transition_manual(frame) +
xlim(-2.5, 2.5)
animate(p, fps = 4, type = "cairo", width = 600, height = 340)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment