Search code examples
rggplot2facet-wrapfacet-grid

Adding an empty space in the middle of a facet_wrapped plot


I'm trying to introduce an empty space in the middle when using ggplot2's facet_wrap feature.

I have eight values of the factor variable I'm using, and the resulting grid looks like this:

existing output

However, if possible, I'd like to end up with this:

desired output

This is, naturally, a square with a hole in it. I'm using cardinal directions, so there's not a "no direction" graph, but I do have everything from northwest to southeast.

I'm aware there are manual solutions to this, which I'm willing to do, but this seems like it should be feasible in an automated sense--to just stick something empty in the middle. I don't need to change the order or anything, just jam a space in there.

Thanks in advance!


Solution

  • One option is ggh4x::facet_manual which via the design argument allows to specify the layout for the panels, e.g. using a "#" you could specify an empty panel and move the "hole" to the middle:

    library(ggplot2)
    library(ggh4x)
    
    dat <- data.frame(
      facet = LETTERS[1:8],
      x = 1,
      y = 1
    )
    
    design = "
    ABC
    D#E
    FGH
    "
    
    ggplot(dat, aes(x, y)) +
      geom_point() +
      ggh4x::facet_manual(~facet, design = design)