Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dgrtwo
Created February 25, 2019 23:56
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgrtwo/d590078aae86e24418a7cf5a9fb31ae3 to your computer and use it in GitHub Desktop.
Save dgrtwo/d590078aae86e24418a7cf5a9fb31ae3 to your computer and use it in GitHub Desktop.
Animation of die rolls
# Code behind this tweet: https://twitter.com/drob/status/1100182329350336513
library(tidyverse)
library(gganimate)
# Setup
options(gganimate.nframes = 200)
set.seed(2019)
simulation <- tibble(roll = 1:10000) %>%
mutate(result = sample(6, n(), replace = TRUE)) %>%
crossing(nrolls = seq(10, 10000, 10)) %>%
filter(roll <= nrolls) %>%
count(nrolls, result)
ggplot(simulation, aes(result, n, fill = factor(result))) +
geom_col(position = "identity", show.legend = FALSE) +
transition_manual(nrolls) +
view_follow() +
scale_x_continuous(breaks = 1:6) +
labs(y = "# of rolls with this result",
title = "Distribution of results after { current_frame } rolls of a six-sided die")
@BroVic
Copy link

BroVic commented Feb 26, 2019

One question please. Is there a reason you didn't pipe your data simulation into the call to ggplot()?

@Aminaba2016
Copy link

please can you tell me how can i extract tweets and their replies about a specific thing and not person

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment