diff --git a/R/guide-colorbar.R b/R/guide-colorbar.R
index 7e71eaba0c..57f9d02757 100644
--- a/R/guide-colorbar.R
+++ b/R/guide-colorbar.R
@@ -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])
)
},
diff --git a/tests/testthat/_snaps/guides/white-to-red-colorbar-thick-black-ticks-green-frame.svg b/tests/testthat/_snaps/guides/white-to-red-colorbar-long-thick-black-ticks-green-frame.svg
similarity index 89%
rename from tests/testthat/_snaps/guides/white-to-red-colorbar-thick-black-ticks-green-frame.svg
rename to tests/testthat/_snaps/guides/white-to-red-colorbar-long-thick-black-ticks-green-frame.svg
index a10cf6f3e1..e5839bc3ff 100644
--- a/tests/testthat/_snaps/guides/white-to-red-colorbar-thick-black-ticks-green-frame.svg
+++ b/tests/testthat/_snaps/guides/white-to-red-colorbar-long-thick-black-ticks-green-frame.svg
@@ -59,21 +59,21 @@
x
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
0.0
0.5
1.0
1.5
2.0
-white-to-red colorbar, thick black ticks, green frame
+white-to-red colorbar, long thick black ticks, green frame
diff --git a/tests/testthat/test-guides.R b/tests/testthat/test-guides.R
index 2ea4d3a696..8b44ffaf5c 100644
--- a/tests/testthat/test-guides.R
+++ b/tests/testthat/test-guides.R
@@ -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")
)
)
)