Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
# Article about why not to use barplots
# Article about being wary of summary statistics and why raw data plots are better than boxplots
# 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)
# 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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.