Skip to content

Instantly share code, notes, and snippets.

View ajstewartlang's full-sized avatar

Andrew Stewart ajstewartlang

View GitHub Profile
@dgrtwo
dgrtwo / dice-rolls.R
Created February 25, 2019 23:56
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)) %>%
download.file("https://images1.westword.com/imager/u/745xauto/9813472/mg_3662.jpg", "img.jpg")
img <- jpeg::readJPEG("img.jpg")
library(ggplot2)
ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) +
annotation_custom(rasterGrob(img,
width = unit(1,"npc"),
height = unit(1,"npc"))) +
geom_point()
unlink("img.jpg")
# somewhat hackish solution to:
# https://twitter.com/EamonCaddigan/status/646759751242620928
# based mostly on copy/pasting from ggplot2 geom_violin source:
# https://github.com/hadley/ggplot2/blob/master/R/geom-violin.r
library(ggplot2)
library(dplyr)
"%||%" <- function(a, b) {