facets: change scales only if not already provided

This commit is contained in:
pvictor 2021-01-05 11:11:24 +01:00
parent 3c252c9f20
commit bdf6e19597
2 changed files with 16 additions and 29 deletions

View File

@ -59,44 +59,29 @@ set_scale <- function(ax, values, scales = c("fixed", "free", "free_y", "free_x"
x <- format_date(x) x <- format_date(x)
x x
} }
fun_axis <- switch( waxis <- switch(
axis, axis,
"x" = ax_xaxis, "x" = "xaxis",
"y" = ax_yaxis "y" = "yaxis"
) )
if (scales == "fixed") { if (scales == "fixed") {
ax <- fun_axis( ax$x$ax_opts[[waxis]]$min <- ax$x$ax_opts[[waxis]]$min %||% fmt(range_vals[1])
ax = ax, ax$x$ax_opts[[waxis]]$max <- ax$x$ax_opts[[waxis]]$max %||% fmt(range_vals[2])
min = fmt(range_vals[1]),
max = fmt(range_vals[2])
)
} else if (scales == "free") { } else if (scales == "free") {
ax <- fun_axis( ax$x$ax_opts[[waxis]]$min <- ax$x$ax_opts[[waxis]]$min %||% character(0)
ax = ax, ax$x$ax_opts[[waxis]]$max <- ax$x$ax_opts[[waxis]]$max %||% character(0)
min = character(0),
max = character(0)
)
} else { } else {
ax <- fun_axis( ax$x$ax_opts[[waxis]]$min <- ax$x$ax_opts[[waxis]]$min %||% fmt(range_vals[1])
ax = ax, ax$x$ax_opts[[waxis]]$max <- ax$x$ax_opts[[waxis]]$max %||% fmt(range_vals[2])
min = fmt(range_vals[1]),
max = fmt(range_vals[2])
)
if (scales == "free_x" & axis == "x") { if (scales == "free_x" & axis == "x") {
ax <- fun_axis( ax$x$ax_opts[[waxis]]$min <- ax$x$ax_opts[[waxis]]$min %||% character(0)
ax = ax, ax$x$ax_opts[[waxis]]$max <- ax$x$ax_opts[[waxis]]$max %||% character(0)
min = character(0),
max = character(0)
)
} }
if (scales == "free_y" & axis == "y") { if (scales == "free_y" & axis == "y") {
ax <- fun_axis( ax$x$ax_opts[[waxis]]$min <- ax$x$ax_opts[[waxis]]$min %||% character(0)
ax = ax, ax$x$ax_opts[[waxis]]$max <- ax$x$ax_opts[[waxis]]$max %||% character(0)
min = character(0),
max = character(0)
)
} }
} }

View File

@ -16,3 +16,5 @@ apex(mpg, aes(displ, cty), type = "scatter") %>%
apex(mpg, aes(displ, cty), type = "scatter") %>% apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_grid(rows = vars(drv), cols = vars(year)) ax_facet_grid(rows = vars(drv), cols = vars(year))
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_grid(vars(drv), vars(cyl))