Does the input contain a ggplot2 scale?

isGGScale(
  x,
  scale = c("continuous", "discrete"),
  aes = c("color", "colour", "fill"),
  nullOK = FALSE
)

Arguments

x

Object.

scale

character(1). Type of scale, either "continuous" or "discrete".

aes

character(1). Aesthetic mapping, either "color"/"colour" or "fill". Note that ggplot2 prefers British spelling.

nullOK

logical(1). If set to TRUE, x may also be NULL.

Value

TRUE on success; FALSE on failure, with cause set.

Note

Updated 2019-09-14.

Examples

library(ggplot2) color_c <- scale_color_gradient(low = "red", high = "blue") class(color_c)
#> [1] "ScaleContinuous" "Scale" "ggproto" "gg"
color_d <- scale_color_manual(values = c("red", "blue")) class(color_d)
#> [1] "ScaleDiscrete" "Scale" "ggproto" "gg"
fill_c <- scale_fill_gradient(low = "red", high = "blue") class(fill_c)
#> [1] "ScaleContinuous" "Scale" "ggproto" "gg"
fill_d <- scale_fill_manual(values = c("red", "blue")) class(fill_d)
#> [1] "ScaleDiscrete" "Scale" "ggproto" "gg"
isGGScale(x = color_c, scale = "continuous", aes = "color")
#> [1] TRUE
isGGScale(x = color_d, scale = "discrete", aes = "color")
#> [1] TRUE
isGGScale(x = fill_c, scale = "continuous", aes = "fill")
#> [1] TRUE
isGGScale(x = fill_d, scale = "discrete", aes = "fill")
#> [1] TRUE