# Example 9.38: dynamite plots, revisited

July 16, 2012
By

(This article was first published on SAS and R, and kindly contributed to R-bloggers)

Dynamite plots are a somewhat pejorative term for a graphical display where the height of a bar indicates the mean, and the vertical line on top of it represents the standard deviation (or standard error). These displays are commonly found in many scientific disciplines, as a way of communicating group differences in means.

Many find these displays troubling. One post entitled them unmitigated evil.
The Vanderbilt University Department of Biostatistics has a formal policy discouraing use of these plots, stating that:

Dynamite plots often hide important information. This is particularly true of small or skewed data sets. Researchers are highly discouraged from using them, and department members have the option to decline participation in papers in which the lead author requires the use of these plots.

Despite the limitations of the display, we believe that there may be times when the display is helpful as a way to compare groups, assuming distributions that are approximately normal. Samuel Brown also described creation of these figures, as a way to encourage computing in R. We previously demonstrated how to create them in SAS and R, and today discuss code created by Randall Pruim to demonstrate how such graphics can be created using lattice graphics within the mosaic package.

R
library(mosaic)dynamitePlot <- function(height, error, names = as.character(1:length(height)),                          significance = NA, ylim = c(0, maxLim), ...) {  if (missing(error)) { error = 0 }  maxLim <- 1.2* max(mapply(sum, height, error))  mError <- min(c(error, na.rm=TRUE))  barchart(height ~ names, ylim=ylim, panel=function(x,y,...) {    panel.barchart(x,y,...)    grid.polyline(c(x,x), c(y, y+error), id=rep(x,2), default.units='native',      arrow=arrow(angle=45, length=unit(mError, 'native')))     grid.polyline(c(x,x), c(y, y-error), id=rep(x,2), default.units='native',      arrow=arrow(angle=45, length=unit(mError, 'native')))     grid.text(x=x, y=y + error + .05*maxLim, label=significance,       default.units='native')  }, ...)}

Much of the code involves setting up the appropriate axis limits, then drawing the lines and adding the text. We can call this new function with an artificial example with 4 groups:
Values <- c(1,2,5,4)Errors <- c(0.25, 0.5, 0.33, 0.12)Names <- paste("Trial", 1:4)Sig <- c("a", "a", "b", "b")dynamitePlot(Values, Errors, names=Names, significance=Sig)

We still don't recommend frequent use of these plots (as other displays may be better (e.g. dotplots for very small sample sizes or violin plots), but having the capability to generate dynamite plots within the lattice framework can be handy.