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?
有谁知道如何更改ggplot2中点图例的背景颜色。我创建了下面的情节,想改变传奇的白色背景?有任何想法吗?
1 个解决方案
#1
12
You can use the legend.key
parameter of theme
. That is
您可以使用theme的legend.key参数。那是
theme(legend.key = element_rect(fill = "black"))
主题(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:
#1
12
You can use the legend.key
parameter of theme
. That is
您可以使用theme的legend.key参数。那是
theme(legend.key = element_rect(fill = "black"))
主题(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: