Created
March 28, 2018 23:31
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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