Skip to content

Commit d1cb617

Browse files
author
Anthony Chiu
committed
Fix tidyverse#2429. Add NEWS item and test cases for value-breaks matching in scale_manual
1 parent c716a54 commit d1cb617

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@
8484

8585
* Increase the default `nbin` of `guide_colourbar()` to place the ticks more precisely (#3508, @yutannihilation).
8686

87+
* Modified `manual_scale` to match `values` with the order of `breaks` whenever
88+
`values` is an unnamed vector. Previously, unnamed `values` would be matched
89+
to the limits of the scale and ignore the order of any `breaks` provided. Note
90+
that this may change the appearance of plots that previously relied on the
91+
unordered behaviour. (#2429, @idno0001)
92+
8793
# ggplot2 3.2.1
8894

8995
This is a patch release fixing a few regressions introduced in 3.2.0 as well as

tests/testthat/test-scale-manual.r

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,17 @@ test_that("generic scale can be used in place of aesthetic-specific scales", {
6767

6868
expect_equal(layer_data(p1), layer_data(p2))
6969
})
70+
71+
test_that("named values do not match with breaks in manual scales", {
72+
s <- scale_fill_manual(values = c("data_red" = "red", "data_black" = "black"),
73+
breaks = c("data_black", "data_red"))
74+
s$train(c("data_black", "data_red"))
75+
expect_equal(s$map(c("data_red", "data_black")), c("red", "black"))
76+
})
77+
78+
test_that("unnamed values match breaks in manual scales", {
79+
s <- scale_fill_manual(values = c("red", "black"),
80+
breaks = c("data_red", "data_black"))
81+
s$train(c("data_red", "data_black"))
82+
expect_equal(s$map(c("data_red", "data_black")), c("red", "black"))
83+
})

0 commit comments

Comments
 (0)