|
29 | 29 | #' z2 = abs(rnorm(100)) |
30 | 30 | #' ) |
31 | 31 | #' |
| 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 | +#' |
32 | 39 | #' # Default colour scale colours from light blue to dark blue |
33 | 40 | #' ggplot(df, aes(x, y)) + |
34 | 41 | #' geom_point(aes(colour = z2)) |
|
54 | 61 | #' scale_colour_gradient(low = "white", high = "black") |
55 | 62 | #' # Avoid red-green colour contrasts because ~10% of men have difficulty |
56 | 63 | #' # 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 | +#' |
57 | 74 | scale_colour_gradient <- function(..., low = "#132B43", high = "#56B1F7", space = "Lab", |
58 | 75 | na.value = "grey50", guide = "colourbar", aesthetics = "colour") { |
59 | 76 | continuous_scale(aesthetics, "gradient", seq_gradient_pal(low, high, space), |
|
0 commit comments