有没有办法在ggplot2中更改图例项之间的间距?我现在有
legend.position ="top"
Run Code Online (Sandbox Code Playgroud)
它会自动生成水平图例.然而,物品的间距非常接近,我想知道如何将它们分开更远.
如何将ggplot2图例移动到绘图底部并将其水平旋转?
示例代码:
library(reshape2) # for melt
df <- melt(outer(1:4, 1:4), varnames = c("X1", "X2"))
p1 <- ggplot(df, aes(X1, X2)) + geom_tile(aes(fill = value))
p1 + scale_fill_continuous(guide = guide_legend())
Run Code Online (Sandbox Code Playgroud)
期望的(近似)结果:

我有一个ggplot2图如下:
library(ggplot2)
ggplot(mtcars, aes(factor(cyl), fill=factor(cyl))) +
geom_bar() +
coord_flip() +
theme(legend.position = 'top') +
guides(fill = guide_legend(title=NULL))
Run Code Online (Sandbox Code Playgroud)
我想在填充元素之间添加间距,如下所示: