Created
July 19, 2018 20:19
-
-
Save ajstewartlang/33b396ae9e9c344639dfcd431cc268d2 to your computer and use it in GitHub Desktop.
Animated violin plots for two sample sizes where no real effect exists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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