patchwork icon indicating copy to clipboard operation
patchwork copied to clipboard

Facet_geo implementation

Open McCartneyAC opened this issue 5 years ago • 5 comments

Hi guys. I tried to implement patchwork with the geofacet package.

Geofacet creates a map-like arrangement of geom_facet() instances so that you can geographically plot data.

My original plot looked something like this

When adding in patchwork to make a summation chart on the right, something about patchwork's grid alignment code un-hid the additional facets that facet_geo creates in the background: https://imgur.com/NwlKXmK

getting two complex packages like this to play along is probably too much to ask, but I thought I should throw it out there.

McCartneyAC avatar Feb 18 '20 03:02 McCartneyAC

This might be also related to an issue I found using facet_nested() from the ggh4x package (https://github.com/teunbrand/ggh4x/)

library(ggplot2)
library(patchwork)

mg <- ggplot(mtcars, aes(x = mpg, y = wt)) + geom_point()
g <- mg + ggh4x::facet_nested(vs + am ~ gear, margins = TRUE)

Works fine

g

Error!

g + g
#> Error in grid.Call.graphics(C_setviewport, vp, TRUE): invalid 'layout.pos.col'

So this might be a more general issue with customised facets? (also similar to this: https://github.com/thomasp85/patchwork/issues/149 )

Created on 2020-03-16 by the reprex package (v0.3.0)

eliocamp avatar Mar 16 '20 19:03 eliocamp

Yes. Patchwork makes some assumptions about facets in order to be able to align them properly. I have yet to formalise a description of these assumptions to guide facet extension developers but this should of course be done

thomasp85 avatar Mar 16 '20 20:03 thomasp85

Hi Thomas,

I think I managed to fix the issue of patchwork compatibility with nested facets at my end. The main issue was the way I stored strips in the gtable object. The following are things I ran into that might make it easier to describe the assumptions.

  • Strips should be named strip-t*, strip-b*, strip-l* or strip-r*.
  • Vertical strips are assumed to be 1 cell wide.
  • Vertical strips can be multiple cells tall.
  • Horizontal strips are assumed to be 1 cell tall.
  • Horizontal strips can be multiple cells wide.

Best wishes, Teun

teunbrand avatar Mar 17 '20 22:03 teunbrand

+1 here for facet_nested and patchwork

brunomioto avatar Feb 06 '22 17:02 brunomioto

@brunomioto Can you post a reprex here for the facet nested issue? I doubt it a patchwork issue.

teunbrand avatar Feb 06 '22 18:02 teunbrand