# code chunk 0 eruptionplot = function(effectsize1,pvalue1,effectsize2,pvalue2, mineffect=0,minsignificance=1,...){ y1 = -log10(pvalue1); y2 = -log10(pvalue2) plot(0,0, type = "n", ylim = c(0,max(y1,y2)), xlim = c(-1,1)*max(abs(range(c(effectsize1, effectsize2)))), xlab = "effect size [arbitrary units]", ylab = "significance [-log10 p-value]", lty = 0.1, lwd = 0.5, cex = 0.3) arrows(effectsize1, y1, effectsize2, y2, length = 0.05, angle = 30, code = 2, col = par("fg"), lty = par("lty"), lwd = par("lwd")) abline(v=c(0,mineffect),col="grey") abline(h=-log10(minsignificance),col="grey") } # code chunk 1 library(ggplot2) set.seed(0) # initialize random generator in order to exactly reproduce the plots here group = as.factor(rep(c("A", "B", "C"), each = 10)) groupeffect = 5*(3-as.numeric(group)) xvar = rep(1:10,3)+groupeffect+rnorm(30,sd=1) yvar = groupeffect+rnorm(30,sd=1) dat = data.frame(group,xvar,yvar) # code chunk 2 fm.1 = lm(yvar ~ xvar) results.1 = fm.1$coefficients[2] summary.fm.1 = summary(fm.1) pval.1 = summary.fm.1$coefficients[2, 4] # code chunk 3 fm.2 = lm(yvar ~ xvar + group) results.2 = fm.2$coefficients[2] summary.fm.2 = summary(fm.2) pval.2 = summary.fm.2$coefficients[2, 4] ggplot(dat, aes(x = xvar, y = yvar, color = group)) + geom_point(shape = 1) + scale_colour_hue(l = 50) + geom_smooth(method = lm, se = FALSE) # code chunk 4 eruptionplot(results.1,pval.1,results.2,pval.2,minsignificance=0.05)