Does the input contain a ggplot2 scale?

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

Arguments

x

Object.

scale

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

aes

character(1). Aesthetic mapping, either "colour" or "fill". Note that ggplot2 prefers British spelling, so we're enforcing that convention here.

nullOK

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

Value

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

Examples

library(ggplot2)
#> Registered S3 methods overwritten by 'ggplot2': #> method from #> [.quosures rlang #> c.quosures rlang #> print.quosures rlang
colour_c <- scale_colour_gradient(low = "red", high = "blue") class(colour_c)
#> [1] "ScaleContinuous" "Scale" "ggproto" "gg"
colour_d <- scale_colour_manual(values = c("red", "blue")) class(colour_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 = colour_c, scale = "continuous", aes = "colour")
#> [1] TRUE
isGGScale(x = colour_d, scale = "discrete", aes = "colour")
#> [1] TRUE
isGGScale(x = fill_c, scale = "continuous", aes = "fill")
#> [1] TRUE
isGGScale(x = fill_d, scale = "discrete", aes = "fill")
#> [1] TRUE