有没有办法在ggplot2中更改图例项之间的间距?我目前有
legend.position ="top"
它会自动生成一个水平图例。然而,这些项目的间距非常接近,我想知道如何将它们隔开得更远。
发布于 2015-07-15 14:04:00
我认为最好的选择是在guides
中使用guide_legend
p + guides(fill=guide_legend(
keywidth=0.1,
keyheight=0.1,
default.unit="inch")
)
注意使用default.unit
,不需要加载grid
包。
发布于 2015-03-07 22:45:45
我用来在水平图例中添加空格的一个简单的修复方法,只需在标签中添加空格(参见下面的摘录):
scale_fill_manual(values=c("red","blue","white"),
labels=c("Label of category 1 ",
"Label of category 2 ",
"Label of category 3"))
发布于 2014-11-17 19:29:51
现在ggplot2
包中已经弃用了opts
,应该改用函数theme
:
library(grid) # for unit()
... + theme(legend.key.height=unit(3,"line"))
... + theme(legend.key.width=unit(3,"line"))
https://stackoverflow.com/questions/11366964
复制相似问题