【发布时间】:2020-06-04 05:42:51
【问题描述】:
我很高兴发现我可以通过将key_glyph = draw_key_rect 添加到我的 geom 图层来更改图例中使用的字形。我想让图例更宽更短,以类似于Timo Grossenbacher 这张地图中的图例:
我尝试调整 scale_fill_manual(guide = guide_legend(keyheight = unit(0.01, units = "mm") , keywidth = unit(40, units = "mm"))) 来改变图例的尺寸,但似乎只有在我将字形变大时才会起作用。我似乎无法将键高调小。
有没有更好的方法来调整图例字形的尺寸?
这里是简化代码:
df <- data_frame(x_value = c(1:10),
y_value = c(rev(1:10)),
value = c("a","a","a","a","b","b","b","b","c","c"))
library(ggplot2)
ggplot(data = df) +
geom_point(aes(x_value, y_value, fill = value),
shape = 21,
size = 9,
key_glyph = draw_key_rect) +
theme(legend.justification = c(0,0), # set which corner of legend legen.position references
legend.position = c(0.05, 0.04)) +
scale_fill_manual(values = c("red", "green", "blue"),
guide = guide_legend(direction = "horizontal",
keyheight = unit(0.01, units = "mm"),
keywidth = unit(40, units = "mm"),
title.position = 'top',
label.position = "bottom"))
【问题讨论】:
-
你也看过here吗?
标签: r ggplot2 legend-properties