Skip to content

Instantly share code, notes, and snippets.

@CnrLwlss
Last active June 14, 2019 16:57
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 CnrLwlss/7c1228541139cf2de456b375d970b5f1 to your computer and use it in GitHub Desktop.
Save CnrLwlss/7c1228541139cf2de456b375d970b5f1 to your computer and use it in GitHub Desktop.
R script demonstrating a few things: 1) drawing boxplots with notches roughly indicating significance of differences 2) stripcharts using transparency to highlight values of high density 3) overlaying boxplot on stripcharts and 4) writing plots as multi-page .pdf reports
# Info about boxplot notches https://sites.google.com/site/davidsstatistics/home/notched-box-plots
# Article about why not to use barplots https://doi.org/10.1371/journal.pbio.1002128
# Article about being wary of summary statistics and why raw data plots are better than boxplots https://www.autodeskresearch.com/publications/samestats
# Generate some fake data
concs = seq(0,10,1)
concobs = rep(concs,each=500)
mdel = function(x) -x^2+10*x+20
vals = mdel(concobs) + rnorm(length(concobs),0,12)
dat = data.frame(conc=concobs,val=vals)
pdf("SyntheticData.pdf")
# Draw a boxplot, with notches indicating whether differences in median are signifiant
boxplot(vals~conc,data=dat,notch=TRUE,xlab="Concentration (gareths)",ylab="Signal (AU)",main="Boxplot with notches")
# Draw a vertical stripchart with transparent points to give an indication of outliers and where most signal is found
stripchart(vals~conc,data=dat,method="jitter",jitter=0.15,vertical=TRUE,pch=16,col=rgb(1,0,0,0.05),xlab="Concentration (gareths)",ylab="Signal (AU)", main="Stripchart with transparency")
stripchart(vals~conc,data=dat,method="jitter",jitter=0.15,vertical=TRUE,pch=16,col=rgb(1,0,0,0.05),xlab="Concentration (gareths)",ylab="Signal (AU)", main="Stripchart and boxplot")
boxplot(vals~conc,data=dat,notch=TRUE,add=TRUE,border=c("black"),boxwex=0.4,outline=FALSE)
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment