【发布时间】:2019-11-17 21:37:35
【问题描述】:
我在互联网上进行了搜索,但找不到解决问题的方法。
所以为了更可靠地说,我们有一个带有两个图例的图表,如下所示:
library(ggplot2)
ggplot() +
geom_point(data = mtcars, aes(x = disp, y = mpg, color = gear),
pch =20, size=18) +
geom_line(data = mtcars, aes(x = disp, y = mpg, size = disp/mpg*100)) +
scale_size(range = c(0,3.5)) +
guides(size = guide_legend("", order = 1, keywidth = 2, keyheight = 1.5),
color = guide_legend("", order = 2, keywidth = 1, keyheight = 1 )) +
labs(x = "disp", y = "mpg") +
geom_text(size=2.7, color = "grey29", vjust=-0.8) +
theme_bw()
# ggsave("trial.png", width = 11.5, height = 8.5)
我可以通过使用更改与大小相关的第一个图例组的间距
size 中的guides 选项。但是,对于表示颜色的第二组,我既不能使整个组更靠近图形,也不能缩小到彩色圆圈之间的大小。
我也尝试过主题中的图例选项,例如legend.spacing.x/y 和legend.key.width/height。这些选项仅适用于第一个图例组。
有没有办法减少不同颜色键之间的尺寸?更改键的大小也很容易发现。
提前致谢。
【问题讨论】:
标签: r ggplot2 legend legend-properties