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,The result looks like this: The code is also available on gitHub.
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)
4 comments:
Very nice! I've given up on dynamite plots after reading all the dire warnings (although I still harbour a secret liking for their simplicity) but I totally agree with you about making R friendly and useful being a good way of spreading the word.
If you want to encourage people to use R then show them how much easier it is to produce a boxplot than a dynamite plot and how much more informative it is.
Why code an inferior plot in several lines when the default R boxplot can be done in one?
George
http://sharpstatistics.co.uk/stats/comparing-data-sets/
Hi George
Fair point. However, I guess my philosophy is that it's easier for us to meet people at their level and then encourage them deeper, as opposed to expecting them to come up to ours.
The function can also be used to demonstrate the difference between the two plotting methods, eg:
aa <- rnorm(100, mean = 50, sd = 20)
bb <- rpois(100, lambda = 65)
cc <- rgamma(100, shape = 5, scale = 10)
heights <- sapply(list(aa, bb, cc), mean)
sds <- sapply(list(aa, bb, cc), sd)
dynamitePlot(heights, sds)
boxplot(aa, bb, cc)
And here you were harassing me last week for doing a dynamite plot in R with an undergrad!
I accept the criticisms of dynamite plots but still like how they can quickly and intuitively convey the main trends. Boxplots contain more information, but they're ugly and need to be explained to people unfamiliar with them (e.g., most undergrads).
Post a Comment