【问题标题】:Adjusting distance between plots调整地块之间的距离
【发布时间】:2014-02-21 19:29:33
【问题描述】:

我有几个要使用grid.arrange() 合并的 ggplot 图

当我合并地块时,每个地块周围都有一个大的白色区域,使它们彼此远离。

有没有办法调整地块之间的距离?以及地块周围白色区域的大小?

【问题讨论】:

    标签: r ggplot2 gridextra


    【解决方案1】:

    您可以使用 ggplot2 中的theme(plot.margin) 函数来减小间距。

    这里是一个简单的工作示例:

    library(grid)
    library(gridExtra)
    library(ggplot2)
    
    x <- seq(1,10,1)
    y <- dnorm(x,mean=10,sd=0.5)
    
    
     # Create p1
    p1 <- qplot(x,y) + theme(plot.margin=unit(c(1,1,-0.5,1),"cm"))
    
    # Create p2
    p2 <- qplot(x,y) + theme(plot.margin=unit(c(-0.5,1,1,1),"cm"))
    
    grid.arrange(p1,p2)
    

    编辑 这四个号码是c(bottom,left,top,right)

    样本输出

    【讨论】:

    • 你能解释一下 unit() 中的 4 个数字是什么意思吗?
    • 编辑了我的答案以引用四个数字。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多