R ggplot2:更改图例和面板之间的间距

R ggplot2:更改图例和面板之间的间距,r,ggplot2,R,Ggplot2,如何在ggplot2 2.2.0中更改图例区域和面板之间的间距 事实上,我认为你提到的选项会起作用。他们似乎为我工作;可能您没有输入适当的值 看看这两个,看看我在说什么: ggplot(dfr,aes(x=x,y=value,fill=variable))+ geom_bar(stat="identity")+ theme(legend.position="top", legend.justification="right", legend.margin

如何在
ggplot2 2.2.0
中更改图例区域和面板之间的间距


事实上,我认为你提到的选项会起作用。他们似乎为我工作;可能您没有输入适当的值

看看这两个,看看我在说什么:

ggplot(dfr,aes(x=x,y=value,fill=variable))+
  geom_bar(stat="identity")+
  theme(legend.position="top",
        legend.justification="right",
        legend.margin=margin(0,0,0,0),
        legend.box.margin=margin(-10,-10,-10,-10))


啊,是的!它确实有效。谢谢价值观已经改变了很多,这不是很奇怪吗?0的边距应该已经使它非常接近图表了?这是否意味着存在另一个我们通过设置负保证金重叠的保证金元素?
ggplot(dfr,aes(x=x,y=value,fill=variable))+
  geom_bar(stat="identity")+
  theme(legend.position="top",
        legend.justification="right",
        legend.margin=margin(0,0,0,0),
        legend.box.margin=margin(0,0,0,0))
ggplot(dfr,aes(x=x,y=value,fill=variable))+
  geom_bar(stat="identity")+
  theme(legend.position="top",
        legend.justification="right",
        legend.margin=margin(0,0,0,0),
        legend.box.margin=margin(-10,-10,-10,-10))
ggplot(dfr,aes(x=x,y=value,fill=variable))+
  geom_bar(stat="identity")+
  theme(legend.position="top",
        legend.justification="right",
        legend.margin=margin(0,0,0,0),
        legend.box.margin=margin(10,10,10,10))