Skip to content

Commit 6cd3d8c

Browse files
committed
add regression tests
1 parent 1f09a31 commit 6cd3d8c

File tree

3 files changed

+134
-1
lines changed

3 files changed

+134
-1
lines changed
Lines changed: 78 additions & 0 deletions
Loading

tests/testthat/test-guides.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,17 @@ test_that("colorbar can be styled", {
205205
)
206206
)
207207
})
208+
209+
test_that("guides can handle multiple aesthetics for one scale", {
210+
df <- data.frame(x = c(1, 2, 3),
211+
y = c(6, 5, 7))
212+
213+
p <- ggplot(df, aes(x, y, color = x, fill = y)) +
214+
geom_point(shape = 21, size = 3, stroke = 2) +
215+
scale_colour_viridis_c(
216+
name = "value",
217+
option = "B", aesthetics = c("colour", "fill")
218+
)
219+
220+
expect_doppelganger("one combined colorbar for colour and fill aesthetics", p)
221+
})

tests/testthat/test-scales.r

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ test_that("Size and alpha scales throw appropriate warnings for factors", {
209209
)
210210
# There should be no warnings for ordered factors
211211
expect_warning(ggplot_build(p + geom_point(aes(size = o))), NA)
212-
expect_warning(ggplot_build(p + geom_point(aes(alpha = o))), NA)
212+
expect_warning(ggplot_build(p + geom_point(aes(alpha = o))), NA)
213213
})
214214

215215
test_that("Shape scale throws appropriate warnings for factors", {
@@ -230,3 +230,44 @@ test_that("Shape scale throws appropriate warnings for factors", {
230230
"Using shapes for an ordinal variable is not advised"
231231
)
232232
})
233+
234+
test_that("Aesthetics can be set independently of scale name", {
235+
df <- data.frame(
236+
x = LETTERS[1:3],
237+
y = LETTERS[4:6]
238+
)
239+
p <- ggplot(df, aes(x, y, fill = y)) +
240+
scale_colour_manual(values = c("red", "green", "blue"), aesthetics = "fill")
241+
242+
expect_equal(layer_data(p)$fill, c("red", "green", "blue"))
243+
})
244+
245+
test_that("Multiple aesthetics can be set with one function call", {
246+
df <- data.frame(
247+
x = LETTERS[1:3],
248+
y = LETTERS[4:6]
249+
)
250+
p <- ggplot(df, aes(x, y, colour = x, fill = y)) +
251+
scale_colour_manual(
252+
values = c("grey20", "grey40", "grey60", "red", "green", "blue"),
253+
aesthetics = c("colour", "fill")
254+
)
255+
256+
expect_equal(layer_data(p)$colour, c("grey20", "grey40", "grey60"))
257+
expect_equal(layer_data(p)$fill, c("red", "green", "blue"))
258+
259+
# color order is determined by data order, and breaks are combined where possible
260+
df <- data.frame(
261+
x = LETTERS[1:3],
262+
y = LETTERS[2:4]
263+
)
264+
p <- ggplot(df, aes(x, y, colour = x, fill = y)) +
265+
scale_colour_manual(
266+
values = c("cyan", "red", "green", "blue"),
267+
aesthetics = c("fill", "colour")
268+
)
269+
270+
expect_equal(layer_data(p)$colour, c("cyan", "red", "green"))
271+
expect_equal(layer_data(p)$fill, c("red", "green", "blue"))
272+
})
273+

0 commit comments

Comments
 (0)