简体   繁体   中英

Spreading out facetted plots (R)

Is there a way to spread facetted plots apart in 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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