Does the input contain a ggplot2 scale?
Source:R/check-scalar-isGgscale.R
check-scalar-isGgscale.Rd
Does the input contain a ggplot2 scale?
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 toTRUE
,x
may also beNULL
.
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