0

I am plotting some time series and the error bars (geom_errorbar) showing the SD of the means. I am using ggplot and I want to make the error bars visible in the legend, like this below (done in MatLab):

Error bar in legend

Is it possible?

  • you can change the legend key function, `GeomErrorbar$draw_key` . [this](https://stackoverflow.com/questions/35703983/how-to-change-angle-of-line-in-customized-legend-in-ggplot2/35710840#35710840) might get you started – user20650 Nov 26 '18 at 23:52
  • 1
    e.g. `GeomErrorbar$draw_key <- function (data, params, size) { data$linetype[is.na(data$linetype)] <- 0 ; segmentsGrob(c(0.2, 0.2, 0.5), c(0.2, 0.8, 0.2), c(0.8, 0.8, 0.5), c(0.2, 0.8, 0.8), gp = gpar(col = alpha(data$colour, data$alpha), lwd = data$size * .pt, lty = data$linetype, lineend = "butt"), arrow = params$arrow) }` – user20650 Nov 27 '18 at 00:00
  • 1
    See also this https://owi.usgs.gov/blog/boxplots/ – Tung Nov 27 '18 at 00:54

0 Answers0