如何在ggplot2中更改图例的背景颜色? [英] How to change background colour of legend in ggplot2?
本文介绍了如何在ggplot2中更改图例的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道如何更改ggplot2中图例的背景颜色.我在下面创建了剧情,想更改图例上的白色背景吗?有什么想法吗?
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?
推荐答案
您可以使用theme
的legend.key
参数.来自?theme
:
You can use the legend.key
parameter of theme
. From ?theme
:
legend.key
:图例键(element_rect()
;从rect
继承)下的背景
legend.key
: background underneath legend keys (element_rect()
; inherits fromrect
)
那是
theme(legend.key = element_rect(fill = "black"))
一个例子:
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"))
产生:
这篇关于如何在ggplot2中更改图例的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文