How to change the background color of a legend in ggplot2?

Does anyone know how to change the background color for the point legend in ggplot2. I created the plot below and would like to change the white background in the legend? Any ideas?

enter image description here

+5
source share
1 answer

You can use the legend.key theme parameter. it

theme(legend.key = element_rect(fill = "black"))

Example:

 a <- seq(1:5) b <- seq(1:5) c <- seq(1:5) d <- data.frame(a, b, c) ggplot(data = d, aes(x = a, y = b, color = factor(c))) + geom_point() + theme(legend.key = element_rect(fill = "yellow")) 

gives:

enter image description here

+9
source

Source: https://habr.com/ru/post/1232469/


All Articles