简体   繁体   English

展开多面图(R)

[英]Spreading out facetted plots (R)

Is there a way to spread facetted plots apart in ggplot2? 有没有办法在ggplot2中分散多面图? As you can see in the picture (the bottom section of my plot), the x-axes are overlapping a bit at the ends of each plot, obscuring the years. 如您在图片中所见(我的绘图的底部),x轴在每个绘图的末端都有些重叠,遮盖了岁月。 I'd like to move them apart. 我想将它们分开。 No matter how much I increase the width when exporting, the values still overlap. 无论我在导出时增加多少宽度,这些值仍然重叠。

My code, if relevant: 我的代码(如果相关):

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

在此处输入图片说明

Since you did not provide a reproducible example, we'll have to make one for you. 由于您没有提供可复制的示例,因此我们必须为您做一个。

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

在此处输入图片说明

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

在此处输入图片说明

This does not suffer from the overlap (can't do all the work for you) but hopefully it's clear what the panel margin settings do. 这不会受到重叠的影响(无法为您完成所有工作),但希望可以清楚地知道面板边距设置的作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM