Zack Weinberg
unread,Oct 19, 2020, 10:33:14 AM10/19/20Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ggplot2
I have (heavily reduced) data with a categorical independent variable
and a continuous dependent variable, one point per category, and error
bars on that point. There are several built-in geoms for plotting
this sort of thing, but they all have trouble with the error bars
becoming invisible when they're very short -- they get hidden behind
the marker for the best estimate of the actual value.
Concretely, here is a sample script that generates two PDF plots (both
of which are attached, for your convenience) and you can see that the
error bar is invisible in one direction on both of the data points.
---
library(ggplot2)
d <- data.frame(
case = c("A", "B"),
obs = c(0.3, 0.6),
obs.lo = c(0.25, 0.59),
obs.hi = c(0.31, 0.7)
)
cairo_pdf("demo-points.pdf", width=2, height=3)
ggplot(d, aes(x=case, y=obs, ymin=obs.lo, ymax=obs.hi)) +
ylim(0,1) +
geom_pointrange()
invisible(dev.off())
cairo_pdf("demo-crossbar.pdf", width=2, height=3)
ggplot(d, aes(x=case, y=obs, ymin=obs.lo, ymax=obs.hi)) +
ylim(0,1) +
geom_crossbar()
invisible(dev.off())
---
What I would like is to plot the `y` aesthetic with a thin horizontal
line and the `ymin..ymax` aesthetic with a thick vertical line with
square endcaps, as shown in the attached "demo-plus.pdf" (which is a
hand edit of demo-crossbar.pdf). I can get the thick vertical line
with geom_linerange() but I can't figure out any way to get the thin
horizontal line. `geom_segment(aes(x=case-0.5, xend=case+0.5))` seems
like it ought to work but gives an error about non-numeric operands to
binary operators (presumably - and +). Can anyone suggest anything?
zw