Skip to content

Commit

Permalink
fix: obtain expected quantity values from manual scale
Browse files Browse the repository at this point in the history
  • Loading branch information
liang09255 committed Jul 25, 2023
1 parent 1f27ffe commit 23237d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/scale-manual.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ manual_scale <- function(aesthetic, values = NULL, breaks = waiver(), ...,
if (n > length(values)) {
cli::cli_abort("Insufficient values in manual scale. {n} needed but only {length(values)} provided.")
}
values
unname(values[seq_len(n)])
}
discrete_scale(aesthetic, "manual", pal, breaks = breaks, limits = limits, ...)
}
10 changes: 10 additions & 0 deletions tests/testthat/test-scale-manual.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ test_that("names of values used in manual scales", {
)
})

test_that("obtain expected quantity values from manual scale", {
for (aesthetics in .all_aesthetics) {
s <- scale_discrete_manual(aesthetics = aesthetics, values = c("8" = "c", "4" = "a", "6" = "b"))
expect_equal(s$palette(1), c("c"))
expect_equal(s$palette(2), c("c", "a"))
expect_equal(s$palette(3), c("c", "a", "b"))
expect_error(s$palette(4), "Insufficient values")
}
})


dat <- data_frame(g = c("B","A","A"))
p <- ggplot(dat, aes(g, fill = g)) + geom_bar()
Expand Down

0 comments on commit 23237d3

Please sign in to comment.