Skip to content

Instantly share code, notes, and snippets.

View ajstewartlang's full-sized avatar

Andrew Stewart ajstewartlang

View GitHub Profile
# 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) {
@ajstewartlang
ajstewartlang / gist:33b396ae9e9c344639dfcd431cc268d2
Created July 19, 2018 20:19
Animated violin plots for two sample sizes where no real effect exists
devtools::install_github('thomasp85/gganimate')
library(tidyverse)
library(gganimate)
#plotting two groups when no difference exists
df <- NULL
set.seed(1111)
sample_size=20
@ajstewartlang
ajstewartlang / gist:89dcdf01c4512a213141a16e9243626d
Last active November 24, 2023 21:15
Hacked together code for animated raincloud plots for N=20 and N=500 where no difference exists in underlying populations
# Usimg @micahgallen's nice raincloud plot code
# https://wellcomeopenresearch.org/articles/4-63
# and fork of benmarwick/geom_flat_violin.R code
# gganimate by Thomas Lin Pedersen - @thomasp85
devtools::install_github('thomasp85/gganimate')
library(tidyverse)
library(gganimate)
library(RColorBrewer)
@ajstewartlang
ajstewartlang / gist:c6eca4722071b318b376af13aab26c2b
Last active July 24, 2018 12:14
animating tweets using rtweet and tidytext for extraction/tidying and gganimate for animation
#Slightly messy code - could easily be improved upon
#new version of gganimate not yet on CRAN so need to download from github with devtools package
#devtools::install_github('thomasp85/gganimate')
library(tidytext)
library(tidyverse)
library(rtweet)
library(gganimate)
library(lubridate)
library(tidyverse)
library(gganimate)
data <- NULL
sample <- NULL
d <- NULL
for (i in (1:100)) {
set.seed(i+1234)
a <- rnorm(25, 1000, 50)
# Note, this uses the new version of gganimate by Thomas Lin Pedersen (@thomasp85) available from:
# https://github.com/thomasp85/gganimate
# Apologies for clunkiness of code below...
library(tidyverse)
library(gganimate)
data <- NULL
sample <- NULL
d <- NULL
## Written by Victor Yu (@VictorYuEpi)
## From https://pastebin.com/44c6GsDM
## playing around with some sports data - tracking the rank of athletes who completed the decathlon at the 2016 Rio Olympics #r #ggplot2 #gganimate #dataviz #Datavisualization
## install/load required packages ####
library(tidyverse)
library(RColorBrewer)
@ajstewartlang
ajstewartlang / gist:422fda3a81f0b7186f940176cbed70d9
Last active November 23, 2018 22:06
100000 samples with N=20 and no difference in population sampled from
library(tidyverse)
df <- NULL
set.seed(1111)
sample_size = 20
for (i in 1:100000) {
a <- rnorm(sample_size, mean = 10, sd = 2)
b <- rnorm(sample_size, mean = 10, sd = 2)
a <- cbind(a, rep ("A", sample_size), rep (i, sample_size))
# Note this uses the new version of gganimate by Thomas Lin Pedersen - @thomasp85
# it is not yet on CRAN so need to use devtools to install it
# devtools::install_github('thomasp85/gganimate')
library(gganimate) # New version of gganimate
library(tidyverse) # All praise the tidyverse
library(MASS) # Needed to sample from multivariate distribution
# Simulating multivariate data with specific covariance structure
# Use the mvrnorm() function from the MASS package
# From @nnstats on Twitter
# Imagine a hockey game where we know that Team A scores exactly 1 goal for sure and Team B takes 20 shots,
# each with a 5.5% chance of going in.
# Which team would you rather be?
# (nothing additional happens if you tie.)
library(tidyverse)
library(gganimate)
set.seed(1234)