Skip to content

Instantly share code, notes, and snippets.

@mfoos
Created March 28, 2018 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfoos/bd20c9726ba8a39c9b6c86a4d05742a9 to your computer and use it in GitHub Desktop.
Save mfoos/bd20c9726ba8a39c9b6c86a4d05742a9 to your computer and use it in GitHub Desktop.
Keeping errorbars solid while showing color AND linetype in the legend for lines in ggplot2
library(ggplot2)
set.seed(1)
test_df <- data.frame(models = rep(paste("Model", LETTERS[1:3]), 3),
x = c(rep(1, 3),
rep(2, 3),
rep(3, 3)),
y = c(1:3,1:3+1+rnorm(3,0,.2),1:3+2)+rnorm(3,0,.3))
test_df$ymax <- test_df$y + .3
test_df$ymin <- test_df$y - .3
ggplot(test_df, aes(x=x, y=y, color=models)) +
geom_errorbar(aes(ymax=ymax, ymin=ymin),
show.legend = FALSE,
lwd=1.2, width=.5) +
geom_line(aes(linetype=models))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment