Skip to content

Instantly share code, notes, and snippets.

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 ajstewartlang/33b396ae9e9c344639dfcd431cc268d2 to your computer and use it in GitHub Desktop.
Save ajstewartlang/33b396ae9e9c344639dfcd431cc268d2 to your computer and use it in GitHub Desktop.
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
for (i in 1:10) {
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))
b <- cbind (b, rep("B", sample_size), rep (i,sample_size))
df <- rbind (df, (rbind(a,b)))
}
df <- as.tibble(df)
colnames(df) <- c("Score","Condition", "Sample")
df$Score <- as.numeric(df$Score)
ggplot(df, aes(x=Condition,y=Score, fill=Condition)) + scale_fill_discrete(guide=FALSE) +
geom_violin() + geom_jitter(width=.05, colour="black", alpha=.1) +
stat_summary(fun.data=mean_cl_boot, geom="pointrange") +
labs (x = "Condition", y="DV", title= paste0("Sample size = ", sample_size)) +
transition_states(Sample, transition_length = 2, state_length = 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment