patchwork icon indicating copy to clipboard operation
patchwork copied to clipboard

insets, and base graphics with layout/mfrow

Open r2evans opened this issue 4 years ago • 0 comments

Thanks for patchwork!

I'm looking at a SO question (https://stackoverflow.com/q/67389256/3358272) that is suggesting the merge of a ggplot object and a base graphics pairs plot. While the premise of inset_element generally works, it appears that the panels within the base plot are being mis-ordered.

(It might not be necessary to use ggblank, but I didn't find a way to start with a base plot.)

ggblank <- ggplot()
gg <- ggplot(mtcars, aes(mpg, disp)) + geom_point()
ggblank +
  inset_element(~pairs(mtcars[,2:4], lower.panel = NULL), left=0, bottom=0, right=1, top=1) +
  inset_element(gg, left=0, bottom=0, right=0.4, top=0.4)

image

The pairs plot looks fine on its own, but it seems that things get a bit screwy internally. I'm inferring that this is similar to base graphic's problem with combining different multiplot methods (layout, mfrow, etc) at one time, is there a way to work around this?

r2evans avatar May 04 '21 17:05 r2evans