Does anybody know how to change the background colour for the points legend in ggplot2. I have created the plot below and would like to change the white background on the legend? Any ideas?

You can use the legend.key parameter of theme. From ?theme:
legend.key: background underneath legend keys (element_rect(); inherits fromrect)
That is
theme(legend.key = element_rect(fill = "black"))
An 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"))
produces:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With