Closed
Description
Many times I find that creating the plots independently in different geoms the continuous axes are not aligned. Is there an efficient way to align axis ranges of plots in a layout. There is not a great way to retrieve axes limits/ranges from gg objects given that the plot only renders on print or in ggplot2::ggplot_build
which basically captures the printed object (see code below).
This solution is very inefficient larger gg objects since you would need to build each plot to ascertain the ranges before actually rendering the layout, so you are rendering the layout multiple times to achieve synchronized axes limits/ranges.
Is there any other way to do this, that would not invoke the whole plot to be rendered?
ref: mjskay/tidybayes#246
axis_rng <- function(p,axis = c('x','y')) {
g <- ggplot2::ggplot_build(p)
axis <- match.arg(axis,several.ok = TRUE)
names(axis) <- axis
lapply(axis,function(x){
g$layout[[sprintf('panel_scales_%s',x)]][[1]]$range$range
})
}
Metadata
Metadata
Assignees
Labels
No labels