Skip to content

Commit

Permalink
Use viridis as default for ordered factors
Browse files Browse the repository at this point in the history
  • Loading branch information
karawoo committed Jul 14, 2017
1 parent 567bc3c commit 9ce7282
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ export(scale_colour_grey)
export(scale_colour_hue)
export(scale_colour_identity)
export(scale_colour_manual)
export(scale_colour_ordinal)
export(scale_colour_viridis_c)
export(scale_colour_viridis_d)
export(scale_fill_brewer)
Expand All @@ -416,6 +417,7 @@ export(scale_fill_grey)
export(scale_fill_hue)
export(scale_fill_identity)
export(scale_fill_manual)
export(scale_fill_ordinal)
export(scale_fill_viridis_c)
export(scale_fill_viridis_d)
export(scale_linetype)
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* Ordered factors now behave differently from unordered factors in some cases.
Ordered factors throw a warning when mapped to shape (unordered factors do
not). Ordered factors do not throw warnings when mapped to size or alpha
(unordered factors do) (@karawoo, #1526).
(unordered factors do). Viridis is the default colour and fill scale for
ordered factors (@karawoo, #1526).

* The `show.legend` parameter now accepts a named logical vector to hide/show
only some aesthetics in the legend (@tutuchan, #1798)
Expand Down
10 changes: 10 additions & 0 deletions R/zxx.r
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#' @usage NULL
scale_colour_discrete <- scale_colour_hue

#' @export
#' @rdname scale_viridis
#' @usage NULL
scale_colour_ordinal <- scale_colour_viridis_d

#' @export
#' @rdname scale_gradient
#' @usage NULL
Expand Down Expand Up @@ -48,6 +53,11 @@ scale_colour_date <- function(...,
#' @usage NULL
scale_fill_discrete <- scale_fill_hue

#' @export
#' @rdname scale_viridis
#' @usage NULL
scale_fill_ordinal <- scale_fill_viridis_d

#' @export
#' @rdname scale_gradient
#' @usage NULL
Expand Down
2 changes: 2 additions & 0 deletions man/scale_viridis.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion tests/testthat/test-viridis.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
context("Viridis")

df <- data.frame(x = 1, y = 1, z = "a")
df <- data.frame(x = 1, y = 1, z = "a", tier = factor("low", ordered = TRUE))

test_that("Viridis scale changes point color", {
p1 <- ggplot(df, aes(x, y, colour = z)) +
Expand All @@ -10,3 +10,9 @@ test_that("Viridis scale changes point color", {
expect_false(layer_data(p1)$colour == layer_data(p2)$colour)
expect_equal(layer_data(p2)$colour, "#440154FF")
})

test_that("Viridis scale is used by default for ordered factors" {
p <- ggplot(df, aes(x, y, colour = tier)) + geom_point()

expect_equal(layer_data(p)$colour, "#440154FF")
})

0 comments on commit 9ce7282

Please sign in to comment.