【问题标题】:ggplot: How to increase spacing between faceted plots?ggplot:如何增加多面图之间的间距?
【发布时间】:2011-04-10 13:06:48
【问题描述】:

我有几个分面直方图(通过下面的命令获得),它们很好地绘制在另一个之下。我想增加它们之间的间距,但是它们很紧。

我查看了doc,但没有找到此参数。

qplot (Happiness.Level, Number.of.Answers, data=mydata, geom="histogram") + facet_grid (Location ~ .) 

【问题讨论】:

  • 我找到了另一种方法来解决这个问题(使用 faces_wrap 而不是 facet_grid,生成的图表更好看)。如果有办法解决原始问题,我仍然感兴趣。
  • 尝试使用 theme_get() 来获得一系列可以使用 opts() 调整的隐藏选项

标签: r ggplot2


【解决方案1】:

只是添加到@rcs 响应:

# Change spacing between facets on both axis
p + theme(panel.spacing = unit(2, "lines"))

# Change horizontal spacing between facets
p + theme(panel.spacing.x = unit(2, "lines"))

# Change vertical spacing between facets
p + theme(panel.spacing.y = unit(2, "lines"))

【讨论】:

    【解决方案2】:

    使用theme函数:

    library(grid)
    
    p + theme(panel.spacing = unit(2, "lines"))
    

    参见此处:Slicing plots generated by ggplot2

    【讨论】:

    • 由于另一个更新,现在咒语是theme(panel.margin = unit(2, "lines"))
    • 更新 - 现在是theme(panel.spacing = unit(1, "lines"))
    • 这在没有 grid 包的情况下工作。根据我的经验,两个并排图的 x 标签经常重叠(lhs 上的最大标签和 rhs 上的最小标签)。修复输出的一种解决方案是ggsave,其宽度大于默认值。但我觉得theme(panel.spacing = unit(1, "lines")) 更好,因为它也适用于弹出式绘图窗口。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多