改变方面之间的水平间距(ggplot2) [英] Alter just horizontal spacing between facets (ggplot2)

查看:797
本文介绍了改变方面之间的水平间距(ggplot2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ggplot2 能够使用参数 panel.margin 选择采用。这似乎改变了水平和垂直间距。有没有办法改变水平或垂直的间距而不改变其他的?

结果和期望结果的例子: p>

  mtcars [,c(cyl,am,gear)] < -  lapply(mtcars [,c cyl,am,gear)],as.factor)

p < - ggplot(mtcars,aes(mpg,wt,group = cyl))+
geom_line (aes(color = cyl))+
geom_point(aes(shape = cyl))+
facet_grid(gear〜am)+
theme_bw()

p + opts(panel.margin = unit(1,lines))

所以它现在看起来像:



我们如何做到这一点看起来更像是:

解决方案

截至2015年7月9日, panel.margin.x panel.margin.y 似乎已经被执行

  p < -  p + theme(panel.margin.x = unit(0.5,lines)+ panel.margin.y =单位(1,行))

截至2016年12月15日,'panel.spacing'和'panel.spacing.x'在r 3.3.2和ggplot2 2.2.0中实现

  p < -  p +主题(panel.spacing.x = unit(0.5,lines),panel.spacing.y = unit(1,lines))


ggplot2 has the ability to change the margins between a faceted plot using the argument panel.margin in opts. This seems to change both horizontal and vertical spacing. Is there a way to change the spacing of either horizontal or vertical without changing the other?

An example with outcome and desired outcome:

mtcars[, c("cyl", "am", "gear")] <- lapply(mtcars[, c("cyl", "am", "gear")], as.factor)

p <- ggplot(mtcars, aes(mpg, wt, group = cyl)) + 
    geom_line(aes(color=cyl)) +
    geom_point(aes(shape=cyl)) + 
    facet_grid(gear ~ am) +
    theme_bw()        

p + opts(panel.margin = unit(1, "lines")) 

So it currently looks like:

How can we make it look more like:

解决方案

As of July 9th, 2015, the panel.margin.x and panel.margin.y seem to have been implemented

p <- p + theme(panel.margin.x=unit(0.5, "lines") + panel.margin.y=unit(1,"lines"))

As of December 15, 2016, 'panel.spacing' and 'panel.spacing.x' is implemented in r 3.3.2 and ggplot2 2.2.0

p <- p + theme(panel.spacing.x=unit(0.5, "lines"),panel.spacing.y=unit(1, "lines"))

这篇关于改变方面之间的水平间距(ggplot2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆