ggplot2图例键之间是否存在最小垂直间距?
ggplot2图例键垂直间距的最小阈值问题
在尝试缩小ggplot2图例中各图例键的垂直间距时,测试发现legend.key.spacing.y参数存在一个绝对最小值——0.001 pt,当设置的间距小于这个值时,图例键之间的间距不会继续缩小。
测试代码如下:
library(ggplot2) # 设置极小间距(0.001 pt) ggplot(mtcars, aes(x = hp, y = mpg, col = as.factor(cyl))) + geom_point() + theme(legend.key.spacing.y = unit(0.001, "pt")) # 设置较大间距(10 pt)作为对比 ggplot(mtcars, aes(x = hp, y = mpg, col = as.factor(cyl))) + geom_point() + theme(legend.key.spacing.y = unit(10, "pt"))
这个最小阈值由ggplot2的布局渲染机制决定,低于该值的参数设置会被自动限制为0.001 pt,无法实现更紧凑的图例键间距。
内容的提问来源于stack exchange,提问作者spindoctor
相关产品推荐
相关产品推荐

