传播刻面图(R)

时间:2016-03-29 20:21:59

标签: r plot ggplot2

有没有办法在ggplot2中传播分面图?正如你在图片中看到的那样(我的情节的底部),x轴在每个图的两端重叠一点,模糊了岁月。我想将它们分开。无论我在导出时增加多少宽度,值仍然会重叠。

我的代码,如果相关:

  ggplot(filter(TotalsRegion, Source!="Total"), aes(x=Date, y=SourceSum, col=Source)) +
   geom_line(size=1) +
   facet_grid(.~Region)

enter image description here

1 个答案:

答案 0 :(得分:5)

由于您没有提供可重复的示例,我们必须为您制作一个。

library(ggplot2)
library(grid)

data(mpg)
mpg$displ <- mpg$displ + 2000
p <- ggplot(mpg, aes(displ, cty))
p <- p + geom_point()
p <- p + facet_grid(. ~ cyl)
p

enter image description here

p <- p + theme(panel.margin.x=unit(20, "pt"))
p

enter image description here

这不会受到重叠影响(无法为您完成所有工作),但希望它能清楚显示面板边距设置的作用。