Dynamite plots in R

April 6, 2012

(This article was first published on The Praise of Insects, and kindly contributed to R-bloggers)

For some time I’ve contemplated creating a function for creating the dynamite plots beloved by many of the applied sciences. There’s a lot of criticism regarding their utility, and there are several ways that present data in a more intelligible way. A search on the subject brings up pages with such emotive titles as “Dynamite plots: unmitigated evil?” and “Why dynamite plots are BAD”. The “Beware of Dynamite” poster sums up the main problem with dynamite plots by concluding “Intentionally or not, a dynamite plot hides more than it reveals”.

All that said, I’m an R advocate. If being able to to create dynamite plots is going to encourage people to use R, I can cope with their inadequacies. Here’s hoping that the paucity of information required to create them makes people reconsider.

dynamitePlot <- function(height, error, names = NA,
        significance = NA, ylim = c(0,maxLim), …){
    maxLim <- 1.1* max(mapply(sum, height, error))
    bp <- barplot(height, names.arg = names, ylim = ylim, ...)
    arrows(x0 = bp, y0 = height, y1 = height + error, angle = 90)
    text(x = bp, y = 0.2 + height + error, labels = significance)

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)

The result looks like this:Dynamite plot The code is also available on gitHub.

To leave a comment for the author, please follow the link and comment on their blog: The Praise of Insects.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)