Skip to content

Single strategy for scale expansion/limiting that works with transformations #3371

Closed
@paleolimbot

Description

@paleolimbot

There are a number of issues that surround expansion and limiting, which is treated differently in various coordinate systems. It would be nice if specifying xlim and ylim were like specifying scale_(x|y)_*(limits = ...), and if scale expansion were identical for scale_(x|y)_continuous(trans = ...) and coord_trans((x|y) = ...).

Related issues:

I think these could almost all be handled in the relatively new ViewScale class, whose objects are currently being created here (this will probably change):

view_scales_from_scale <- function(scale, coord_limits = NULL, expand = TRUE) {
expansion <- if (expand) expand_default(scale) else expand_scale(0, 0)
limits <- scale$get_limits()
if (is.null(coord_limits)) {
continuous_range <- scale$dimension(expansion, limits)
} else {
continuous_range <- range(scale$transform(coord_limits))
continuous_range <- expand_range4(continuous_range, expansion)
}
aesthetic <- scale$aesthetics[1]
view_scales <- list(
view_scale_primary(scale, limits, continuous_range),
sec = view_scale_secondary(scale, limits, continuous_range),
arrange = scale$axis_order(),
range = continuous_range
)
names(view_scales) <- c(aesthetic, paste0(aesthetic, ".", names(view_scales)[-1]))
view_scales
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions