Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error bar ticks |--o--| don't draw for more then three conditions in dotplot

Tags:

plot

r

lattice

This question is an unexpected follow-up from Draw vertical ending of error bar line in dotplot. While the quoted question was succesfully resolved - there is a caveat. When I introduce more then three conditions to dotplot it doesn't want to draw the vertical ticks |--o--| in the endings of error bars.

As @Josh suggested in the comments, I injected browser() into first line of function that draws updated panel.Dotplot to see what goes wrong, but it didn't come out with anything that helps me to solve it. Here is an example code for four-conditions Dotplot() with updated panel.Dotplot function that doesn't work. It will work, if you decrease number of conditions (check answer for the question quoted above):

require(Hmisc)
#Fake conditions
mean = c(1:18)
lo = mean-0.2
up = mean+0.2
name = c("a","b","c")
cond1 = c("A","B","C")
cond2 = c(rep("E1",9),rep("E2",9))
d = data.frame (name = rep(name,6), mean, lo, up, 
                cond1=rep(cond1,each=3,times=2), cond2)
# Create the customized panel function
mypanel.Dotplot <- function(x, y, ...) {
       panel.Dotplot(x,y,...)
       tips <- attr(x, "other")
       panel.arrows(x0 = tips[,1], y0 = y,x1 = tips[,2], 
                y1 = y,length = 0.1, unit = "native",
                angle = 90, code = 3)
}
#Draw Dotplot - `panel.Dotplot` doesn't change anything
setTrellis()
Dotplot(name ~ Cbind(mean,lo,up) | cond1 * cond2, data=d, ylab="", xlab="",col=1,
        panel = mypanel.Dotplot)

enter image description here

like image 906
Geek On Acid Avatar asked Feb 28 '12 20:02

Geek On Acid


People also ask

What do the error bars represent?

An error bar is a line through a point on a graph, parallel to one of the axes, which represents the uncertainty or variation of the corresponding coordinate of the point.

What do overlapping error bars mean?

If two SEM error bars do overlap, and the sample sizes are equal or nearly equal, then you know that the P value is (much) greater than 0.05, so the difference is not statistically significant.

How do you interpret error bars on a line graph?

The length of an Error Bar helps reveal the uncertainty of a data point: a short Error Bar shows that values are concentrated, signalling that the plotted average value is more likely, while a long Error Bar would indicate that the values are more spread out and less reliable.


1 Answers

The error bars are in fact being rendered, but are not visible due to their very short length (± 0.2 units). Increasing the error to ± 1 results in the following (I've also increased the length specified in panel.arrows - i.e. the error bar cap length - to 0.5):

lattice error bars

If your true data is so precise relative to the range of x-values then you might want to consider smaller points (so they aren't as prone to obscuring the error bars) or a layout that exaggerates the x axis. For example, the following uses your original error of ± 0.2 units, and your original arrow cap length of 0.1:

Dotplot(name ~ Cbind(mean,lo,up) | cond1 * cond2, data=d, ylab="", xlab="",
  col=1, panel = mypanel.Dotplot, pch=20, cex=0.4, layout=c(1, 6), strip=FALSE,
  strip.left=strip.custom(par.strip.text=list(cex=0.75), bg=0, fg=0))

lattice precise error bars

like image 70
jbaums Avatar answered Sep 25 '22 15:09

jbaums