Skip to content

Commit cc660da

Browse files
Megan Beckettpaleolimbot
authored andcommitted
Improve documentation for scale_*_gradient (#3407, fixes #3299)
* Add examples for na.value = NA * Addressed PR documentation changes
1 parent b771c50 commit cc660da

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

R/scale-gradient.r

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
#' z2 = abs(rnorm(100))
3030
#' )
3131
#'
32+
#' df_na <- data.frame(
33+
#' value = seq(1, 20),
34+
#' x = runif(20),
35+
#' y = runif(20),
36+
#' z1 = c(rep(NA, 10), rnorm(10))
37+
#' )
38+
#'
3239
#' # Default colour scale colours from light blue to dark blue
3340
#' ggplot(df, aes(x, y)) +
3441
#' geom_point(aes(colour = z2))
@@ -54,6 +61,16 @@
5461
#' scale_colour_gradient(low = "white", high = "black")
5562
#' # Avoid red-green colour contrasts because ~10% of men have difficulty
5663
#' # seeing them
64+
#'
65+
#'# Use `na.value = NA` to hide missing values but keep the original axis range
66+
#' ggplot(df_na, aes(x = value, y)) +
67+
#' geom_bar(aes(fill = z1), stat = "identity") +
68+
#' scale_fill_gradient(low = "yellow", high = "red", na.value = NA)
69+
#'
70+
#' ggplot(df_na, aes(x, y)) +
71+
#' geom_point(aes(colour = z1)) +
72+
#' scale_colour_gradient(low = "yellow", high = "red", na.value = NA)
73+
#'
5774
scale_colour_gradient <- function(..., low = "#132B43", high = "#56B1F7", space = "Lab",
5875
na.value = "grey50", guide = "colourbar", aesthetics = "colour") {
5976
continuous_scale(aesthetics, "gradient", seq_gradient_pal(low, high, space),

man/scale_gradient.Rd

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

0 commit comments

Comments
 (0)