Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions R/scale-gradient.r
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
#' z2 = abs(rnorm(100))
#' )
#'
#' df_na <- data.frame(
#' value = seq(1, 20),
#' x = runif(20),
#' y = runif(20),
#' z1 = c(rep(NA, 10), rnorm(10))
#' )
#'
#' # Default colour scale colours from light blue to dark blue
#' ggplot(df, aes(x, y)) +
#' geom_point(aes(colour = z2))
Expand All @@ -54,6 +61,16 @@
#' scale_colour_gradient(low = "white", high = "black")
#' # Avoid red-green colour contrasts because ~10% of men have difficulty
#' # seeing them
#'
#'# Use `na.value = NA` to hide missing values but keep the original axis range
#' ggplot(df_na, aes(x = value, y)) +
#' geom_bar(aes(fill = z1), stat = "identity") +
#' scale_fill_gradient(low = "yellow", high = "red", na.value = NA)
#'
#' ggplot(df_na, aes(x, y)) +
#' geom_point(aes(colour = z1)) +
#' scale_colour_gradient(low = "yellow", high = "red", na.value = NA)
#'
scale_colour_gradient <- function(..., low = "#132B43", high = "#56B1F7", space = "Lab",
na.value = "grey50", guide = "colourbar", aesthetics = "colour") {
continuous_scale(aesthetics, "gradient", seq_gradient_pal(low, high, space),
Expand Down
17 changes: 17 additions & 0 deletions man/scale_gradient.Rd

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