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

时间:2016-12-28 13:14:51

标签: r ggplot2

如何在legend.margin

中更改图例区域和面板之间的间距

enter image description here

legend.box.margin

更改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)) myCount ['a','b'] ['1','2'] => ['a','b','b'] 似乎无能为力。

myCount :: [Char] -> [Int] -> [Char]       
myCount [] [] = []
myCount (x:xs) (y:ys) =  replicate y x && myCount xs ys

1 个答案:

答案 0 :(得分:9)

实际上,我认为你提到的选项会起作用。他们似乎对我有用;也许你没有输入适当的值。

看看这些2,看看我在说什么:

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))

enter image description here

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))

enter image description here