Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve aesthetics in colourbar merge #5328

Merged
merged 3 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
* `guide_coloursteps()` and `guide_bins()` sort breaks (#5152).
* `guide_axis()` gains a `cap` argument that can be used to trim the
axis line to extreme breaks (#4907).
* `guide_colourbar()` and `guide_coloursteps()` merge properly when one
of aesthetics is dropped (#5324).

* `geom_label()` now uses the `angle` aesthetic (@teunbrand, #2785)
* 'lines' units in `geom_label()`, often used in the `label.padding` argument,
Expand Down
2 changes: 2 additions & 0 deletions R/guide-colorbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ GuideColourbar <- ggproto(
},

merge = function(self, params, new_guide, new_params) {
new_params$key$.label <- new_params$key$.value <- NULL
params$key <- vec_cbind(params$key, new_params$key)
return(list(guide = self, params = params))
},

Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-guides.R
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,26 @@ test_that("guide_coloursteps and guide_bins return ordered breaks", {
expect_true(all(diff(key$.value) < 0))
})

test_that("guide_colourbar merging preserves both aesthetics", {
# See issue 5324

scale1 <- scale_colour_viridis_c()
scale1$train(c(0, 2))

scale2 <- scale_fill_viridis_c()
scale2$train(c(0, 2))

g <- guide_colourbar()
p <- g$params

p1 <- g$train(p, scale1, "colour")
p2 <- g$train(p, scale2, "fill")

merged <- g$merge(p1, g, p2)

expect_true(all(c("colour", "fill") %in% names(merged$params$key)))
})

# Visual tests ------------------------------------------------------------

test_that("axis guides are drawn correctly", {
Expand Down
Loading