# This is just a near-copy of the ggplot one except it calls
# expand_limits_scale_vctr instead of expand_limits_scale
view_scales_from_scale_vctr <- function(scale, coord_limits = NULL,
expand = TRUE) {
if (!inherits(scale, "ScaleContinuousVctr")) {
.int$view_scales_from_scale(scale, coord_limits = coord_limits,
expand = expand)
} else {
expansion <- .int$default_expansion(scale, expand = expand)
limits <- scale$get_limits()
newrange <- expand_limits_scale_vctr(scale, expansion, limits,
coord_limits = coord_limits)
aesthetic <- scale$aesthetics[1]
view_scales <- list(
.int$view_scale_primary(scale, limits, newrange),
sec = .int$view_scale_secondary(scale, limits, newrange),
arrange = scale$axis_order(),
range = newrange
)
names(view_scales) <- c(aesthetic, paste0(aesthetic, ".",
names(view_scales)[-1]))
view_scales
}
}
# This does a similar job as expand_limits_continuous_trans, but leaves the
# implementation details to the class of the limits.
expand_limits_scale_vctr <- function(scale, expand = expansion(0, 0),
limits = waiver(),
coord_limits = NULL) {
if (!inherits(scale, "ScaleContinuousVctr")) {
.int$expand_limits_scale(scale = scale, expand = expand,
limits = limits, coord_limits = coord_limits)
} else {
limits <- limits %|W|% scale$get_limits()
if (is.null(limits)) {
return()
}
if (!(is.numeric(expand) && length(expand) %in% c(2,4))) {
rlang::abort("`expand` must be a numeric vector with 1 or 2 elements")
}
if (length(expand) == 2) {
expand <- c(expand, expand)
}
if (is.null(coord_limits)) {
coord_limits <- vec_cast(NA, limits)
coord_limits <- vec_recycle(coord_limits, vec_size(limits))
}
vec_expand_limits(limits, expand = expand, coord_limits = coord_limits)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.