The package ggh4x provides an extension to base ggplot2 package with some useful additional functionality.
grid facets with multiple distinct subplots
In ggplot2 we can have a facet_grid plot that have scales different for each row and column by setting scales=”free”. However to get different scales for individual facets we would need to use facet_wrap.
However if we now implement facet_grid with ggh4x, we are able to scale the x and y-axis distinctly within each facet of the grid if we use the option ‘independent’. To do this we can specify a scales object ‘position_scales’ which defines the scale for each facet.