I create a figure in which I have a line and trust groups around it. For this, I use both geom_line and geom_ribbon in ggplot2 in R. The problem is how to deal with the legend. Slashes are added in it, and after a long search, I understand that this is a common problem. Most of the solutions I found are for barriers (e.g. ggplot cookbook). I also found solutions to suppress it, but that did not work for me.
Below I have three plots showing the problem. Firstly, when I am just building a line, it looks good. Then, when I add the ribbon portion of the graph, slashes are added. The third plot is how I want it to look (a dash, obviously). How to achieve this?

Edit: To be clear, I want this to be in the following figure (which I fixed with MS Paint):

library(ggplot2) library(gridExtra) set.seed(1) y <- sin(seq(1, 2*pi, length.out = 100)) x <- 1:100 plotdata <- data.frame(x=x, y=y, lower = (y+runif(100, -1, -0.5)), upper = (y+runif(100, 0.5, 1))) h1 <- ggplot(plotdata) + geom_line(aes(y=y, x=x, colour = "sin")) h2 <- h1 + geom_ribbon(aes(ymin=lower, ymax=upper, x=x, colour = "bands"), alpha = 0.3) h3 <- h2 + scale_colour_manual(name='', values=c("bands" = "grey", "sin" = "blue")) grid.arrange(h1, h2, h3)
r plot ggplot2
hejseb
source share