You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
free_* really does two things there though: It frees the scale of the axis – the pixel distance between the breaks – and it frees the absolute location of the scale – whether the break at 5 happens at the same horizontal point across facets.
I would love to have an option to scales that allows me to free location while maintaining scale. That is, vertical distances within each facet would correspond to the same absolute differences in the variable being plotted, but those differences might occur from another baseline.
An admittedly very hacky demonstration:
iris|>
group_by(Sepal.Width) |>
summarize(across(ends_with('Length'), mean)) |>tidyr::pivot_longer(ends_with('Length')) ->plot_dataplot_data|>
summarize(across(value, list(min=min, max=max)), .by=name) |>
mutate(
range=value_max-value_min,
midpoint=value_min+range/2
) |>
mutate(
# center on the midpoint of the largest range among the facetsmax_range= max(range),
axis_min=midpoint-max_range/2,
axis_max=midpoint+max_range/2
) ->facet_specmake_facet<-function(df, x_var, axis_min, axis_max) {
df|>
filter(name==x_var) |>
ggplot(aes(Sepal.Width, value)) +
geom_line() +
facet_wrap(~name) +
coord_cartesian(ylim=c(axis_min, axis_max))
}
facet_spec|>
rowwise() |>
mutate(plots=list(make_facet(plot_data, name, axis_min, axis_max))) |>
pull(plots) |>patchwork::wrap_plots()
The text was updated successfully, but these errors were encountered:
If you pre-calculate the maximum range per facet, you can just use a function as the limits argument that will set a consistent range. I'm unsure whether this is widely applied enough to merit an additional option in facets.
When facetting over things with different range, I currently have the option to give all facets the same axis limits, like so:
or to free axes completely, like so:
free_*
really does two things there though: It frees the scale of the axis – the pixel distance between the breaks – and it frees the absolute location of the scale – whether the break at5
happens at the same horizontal point across facets.I would love to have an option to
scales
that allows me to free location while maintaining scale. That is, vertical distances within each facet would correspond to the same absolute differences in the variable being plotted, but those differences might occur from another baseline.An admittedly very hacky demonstration:
The text was updated successfully, but these errors were encountered: