Automatically select appropriate color scale
Aesthetics used in ggplot.
Color palette.
An optional data.frame to choose the right type for variables.
Scale to use according to the variable used
in fill/color aesthetic : "discrete" or "continuous".
Ignored if data is provided: it will be guessed from data.
Reverse colors order or not.
a list
library(ggplot2)
# Automatic guess according to data
which_pal_scale(
mapping = aes(fill = Sepal.Length),
palette = "ggplot2",
data = iris
)
#> $scales
#> [1] "scale_fill_gradient"
#>
#> $args
#> list()
#>
which_pal_scale(
mapping = aes(fill = Species),
palette = "ggplot2",
data = iris
)
#> $scales
#> [1] "scale_fill_hue"
#>
#> $args
#> $args$scale_fill_hue
#> $args$scale_fill_hue$direction
#> [1] 1
#>
#>
#>
# Explicitly specify type
which_pal_scale(
mapping = aes(color = variable),
palette = "Blues",
color_type = "discrete"
)
#> $scales
#> [1] "scale_color_brewer"
#>
#> $args
#> $args$scale_color_brewer
#> $args$scale_color_brewer$palette
#> [1] "Blues"
#>
#> $args$scale_color_brewer$direction
#> [1] 1
#>
#>
#>
# Both scales
which_pal_scale(
mapping = aes(color = var1, fill = var2),
palette = "Blues",
color_type = "discrete",
fill_type = "continuous"
)
#> $scales
#> [1] "scale_fill_distiller" "scale_color_brewer"
#>
#> $args
#> $args$scale_fill_distiller
#> $args$scale_fill_distiller$palette
#> [1] "Blues"
#>
#> $args$scale_fill_distiller$direction
#> [1] 1
#>
#>
#> $args$scale_color_brewer
#> $args$scale_color_brewer$palette
#> [1] "Blues"
#>
#> $args$scale_color_brewer$direction
#> [1] 1
#>
#>
#>