【发布时间】:2020-07-23 12:26:14
【问题描述】:
有没有办法用ggplot2改变图例中键的宽度和高度?在以下示例中,我想将图例中的点替换为可以调整宽度和高度的矩形。我尝试使用keywidth 没有成功。
library(ggplot2)
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point() +
theme(
legend.position = "top",
legend.title = element_blank()
) +
guides(
color = guide_legend(
label.position = "top",
override.aes = list(shape = 15, size = 5),
keywidth = unit(2, "cm") # This is not giving me what I was expecting.
)
)
由reprex package (v0.3.0) 于 2020 年 7 月 23 日创建
【问题讨论】:
-
而不是图表方块中的点,你想要吗?
-
我想在图中使用点(这已经可以了),但在图例中使用矩形。目前,我能得到的最接近的是使用正方形(形状 = 15)。