Skip to content

Commit 348b26f

Browse files
yutannihilationhadley
authored andcommitted
Do not use ordered factor for viridis example (#2664)
* do not use ordered factor for viridis example * Update viridis examples using txhousing * Fix typo
1 parent 78d4b7a commit 348b26f

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

R/scale-viridis.r

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,36 @@
1818
#' @rdname scale_viridis
1919
#' @export
2020
#' @examples
21+
#' # viridis is the default colour/fill scale for ordered factors
2122
#' dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
22-
#' (d <- ggplot(dsamp, aes(carat, price)) +
23-
#' geom_point(aes(colour = clarity)))
23+
#' ggplot(dsamp, aes(carat, price)) +
24+
#' geom_point(aes(colour = clarity))
25+
#'
26+
#' # Use viridis_d with discrete data
27+
#' txsamp <- subset(txhousing, city %in%
28+
#' c("Houston", "Fort Worth", "San Antonio", "Dallas", "Austin"))
29+
#' (d <- ggplot(data = txsamp, aes(x = sales, y = median)) +
30+
#' geom_point(aes(colour = city)))
2431
#' d + scale_colour_viridis_d()
2532
#'
2633
#' # Change scale label
27-
#' d + scale_colour_viridis_d("Diamond\nclarity")
34+
#' d + scale_colour_viridis_d("City\nCenter")
2835
#'
2936
#' # Select palette to use, see ?scales::viridis_pal for more details
3037
#' d + scale_colour_viridis_d(option = "plasma")
3138
#' d + scale_colour_viridis_d(option = "inferno")
3239
#'
33-
#' \donttest{
3440
#' # scale_fill_viridis_d works just the same as
3541
#' # scale_colour_viridis_d but for fill colours
36-
#' p <- ggplot(diamonds, aes(x = price, fill = cut)) +
37-
#' geom_histogram(position = "dodge", binwidth = 1000)
42+
#' p <- ggplot(txsamp, aes(x = median, fill = city)) +
43+
#' geom_histogram(position = "dodge", binwidth = 15000)
3844
#' p + scale_fill_viridis_d()
3945
#' # the order of colour can be reversed
4046
#' p + scale_fill_viridis_d(direction = -1)
41-
#' }
4247
#'
4348
#' # Use viridis_c with continous data
44-
#' v <- ggplot(faithfuld) +
45-
#' geom_tile(aes(waiting, eruptions, fill = density))
46-
#' v
49+
#' (v <- ggplot(faithfuld) +
50+
#' geom_tile(aes(waiting, eruptions, fill = density)))
4751
#' v + scale_fill_viridis_c()
4852
#' v + scale_fill_viridis_c(option = "plasma")
4953
scale_colour_viridis_d <- function(..., alpha = 1, begin = 0, end = 1,

man/scale_viridis.Rd

Lines changed: 15 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)