相关疑难解决方法(0)

ggplot2,顶部和边缘的传奇

考虑以下:

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"))
Run Code Online (Sandbox Code Playgroud)

输出看起来像这样: ggplot2输出plot.margin=unit(x=c(0,0,0,0),units="mm")传说上方有一个不寻常的白色(红色)空间.有谁知道如何解决这个问题?

谢谢你的任何提示.

真诚的,约翰

graphics r ggplot2

23
推荐指数
3
解决办法
3万
查看次数

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

如何更改图例区域和面板之间的间距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")
Run Code Online (Sandbox Code Playgroud)

改变legend.marginlegend.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))
Run Code Online (Sandbox Code Playgroud)

r ggplot2

13
推荐指数
2
解决办法
7173
查看次数

标签 统计

ggplot2 ×2

r ×2

graphics ×1