Dynamite plots in R

[This article was first published on The Praise of Insects, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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 about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)