使用ggplot2,是否有一种方法可以指定基于绘图面板大小缩放的颜色条宽度?
也就是说,legend.key.width可以提供什么,以使得关键字的相对宽度保持不变,而与图形的大小无关?
也就是说,legend.key.width可以提供什么,以使得关键字的相对宽度保持不变,而与图形的大小无关?
ggplot(mpg) +
geom_point(aes(cty, hwy, color = year)) +
theme(legend.position = "bottom",
legend.key.width = unit(0.1, "npc")) # not relative
# or could it be done with a custom theme?
my_theme <- function() {
theme_bw() %+replace%
theme(legend.position = "bottom", ?)
ggplot(mpg) +
geom_point(aes(cty, hwy, color = year)) +
my_theme()
dev.size()
应该是以英寸为单位的,并且我们在unit
调用中指定了“inches”,因此将其除以二应该可以工作。我不确定这是否是ggplot
中计算grob大小的内部方式的问题。 - Allan Cameron