考虑以下:
library(ggplot2)
library(grid)
ggplot(diamonds, aes(clarity, fill=cut)) + 
  geom_bar() +   
  theme(
    plot.margin=unit(x=c(0,0,0,0),units="mm"),
    legend.position="top",
    plot.background=element_rect(fill="red")) +
  guides(fill=guide_legend(title.position="top"))
输出看起来像这样:
 在
在plot.margin=unit(x=c(0,0,0,0),units="mm")传说上方有一个不寻常的白色(红色)空间.有谁知道如何解决这个问题?
谢谢你的任何提示.
真诚的,约翰
如何更改图例区域和面板之间的间距ggplot2 2.2.0?
library(ggplot2)
library(dplyr)
library(tidyr)
dfr <- data.frame(x=factor(1:20),y1=runif(n=20)) %>%
        mutate(y2=1-y1) %>%
        gather(variable,value,-x)
ggplot(dfr,aes(x=x,y=value,fill=variable))+
  geom_bar(stat="identity")+
  theme(legend.position="top",
        legend.justification="right")
改变legend.margin或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))