1 year ago

#283418

test-img

crusher083

Remove a dark background from `geom_line` `ggplot2` legend

I am trying to build a plot with geom_rect and geom_line. I don't know how to remove dark color in the legend background after placing geom_line.

Here's my code

gp <- (gp 
       + ggplot2::geom_rect(data = dd5,
                              mapping = ggplot2::aes(xmin = begin, xmax = end+expPer,
                                                     ymin = order+0.35, ymax = order+0.25,
                                                     fill = description),
                              show.legend = T)
       
       + ggplot2::geom_line(data = dd6e, 
                            mapping = ggplot2::aes(x = begin,
                                                   y = order + 0.4*end,
                                                   group = order,
                                                   color = description),
                            show.legend = T)
       + guides(fill = guide_legend(override.aes = list(linetype = c(0))))
       + theme(axis.text.y=element_blank(),  #remove y axis labels
               axis.ticks.y=element_blank()) #remove y axis ticks
);  

And here's the output, where the background is denoted in red. enter image description here
Ideally, I'd also like to merge both descriptions into a single legend. Cheers!
[EDIT] I tried:

  • scale_colour_manual and it only modifies the colour of the first line
  • scale_fill_manual and it modifies all rectangles except first one :/

r

ggplot2

legend-properties

0 Answers

Your Answer

Accepted video resources