Skip to content

Fix colourbar's ticks.length argument not working #5529

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

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 3 additions & 6 deletions R/guide-colorbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -439,14 +439,11 @@ GuideColourbar <- ggproto(
"horizontal" = c("bottom", "top"),
"vertical" = c("right", "left")
)
elements$ticks_length <- rep(elements$ticks_length, length.out = 2)
elem1 <- elem2 <- elements
elem1$ticks_length <- elements$ticks_length[2]
elem2$ticks_length <- elements$ticks_length[1]
ticks_length <- rep(elements$ticks_length, length.out = 2)

grobTree(
Guide$build_ticks(pos, elem1, params, position[1]),
Guide$build_ticks(pos, elem2, params, position[2])
Guide$build_ticks(pos, elements, params, position[1], ticks_length[1]),
Guide$build_ticks(pos, elements, params, position[2], ticks_length[2])
)
},

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions tests/testthat/test-guides.R
Original file line number Diff line number Diff line change
Expand Up @@ -708,14 +708,15 @@ test_that("colorbar can be styled", {
p + scale_color_gradient(low = 'white', high = 'red')
)

expect_doppelganger("white-to-red colorbar, thick black ticks, green frame",
expect_doppelganger("white-to-red colorbar, long thick black ticks, green frame",
p + scale_color_gradient(
low = 'white', high = 'red',
guide = guide_colorbar(
frame = element_rect(colour = "green"),
frame.linewidth = 1.5 / .pt,
ticks.colour = "black",
ticks.linewidth = 2.5 / .pt
ticks.linewidth = 2.5 / .pt,
ticks.length = unit(0.4, "npc")
)
)
)
Expand Down