I have written a code to display a dynamite plot the way I like (I modified a function I found on github)
I have made a mock data set for the example, and have been playing around with the code to try and get the error bars to not only go above each bar plot, but to extend below each bar plot as well. This has been achieved. However, the error from binomial models is not always symmetrical, and I would like to adjust for this.
Lets say, for this example, I would like the error around treatment T2 in the graph below to be +8 and -13. How could this be achieved?
Here is the code for this particular example that I have been working with:
#here is the dynamite plot function
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)
arrows(x0 = bp, y0 = height, y1 = height - error, angle = 90)
text(x = bp, y = 2 + height + error, labels = significance, cex=1.5)
}
#Trial data
trial <- data.frame( "cats" = character(0))
x <- c("T2", "T1", "C")
df <- data.frame("cats" = x)
#Values for dynamite plot
Values <- c(72,60,20) # % on y Axis
Errors <- c(8,13,12) # the standard errors (**this is where the problem is** (I think), lets pretend I want the error bars to extend from (4:8), (3:13), and (6:12) for each "treatment" respectively (T2, T1, and C)
Names <- df$cats
Sig <- c("A","A","B") # letters denoting statistical significance (test not shown here)
par(mar=c(5,5,2,1))
pallet <- c('111','222','333')
#make plot
dynamitePlot(Values, Errors, significance = Sig, names = df$cats,col=pallet, width=c(0.03,0.03,0.03,0.03,0.03), ylim = c(0,100), cex.axis=1.5, cex.lab=1.5,ylab="Percent [%]", xlab="Treatment")
Another arrow()
line in dynamitePlot()
can display the lower half:
arrows(x0 = bp, y0 = height, y1 = height - error, angle = 90)