With facet_zoom() from the ggforce package one can create nice zooms to highlight certain regions of a plot. Unfortunately, when zooming in on the y axis the original plot is always on the right side.
Is there a way to place the original plot on the left?
This would feel more intuitive to first look at the main plot and then at the zoomed region. As an example I would like to swap the position of the two facets in this plot:
(No reproducible example added, since I believe this is a question about the existence of a certain functionality.)
I've tweaked the current code for
FacetZoom
on GitHub to swop the horizontal order from [zoom, original] to [original, zoom]. The changes aren't complicated, but they are scattered throughoutdraw_panels()
function's code, so the full code is rather long.Result:
Code used (I've commented out the original code, where modified code is used, & indicated the packages for functions from other packages):
Note:
create_panels
andexpansion
are un-exported functions from the ggforce package, so I referenced them with triple colons. This isn't robust for writing packages, but should suffice as a temporary workaround.Update 30 Oct 2019: A suggestion for those seeing errors like
Invalid 'type' (list) of argument
after trying to use this solution as-is. The issue is likely due to updates made to theggforce
package since this solution was developed. To get the code in this solution working again, install the version ofggforce
that was available when the solution was developed. This can be done with thedevtools
package pointing to the4008a2e
commit:devtools::install_github("thomasp85/ggforce", ref = '4008a2e')