Generate colors using the name of a color palette.
Arguments
- x
character
name of the color palette (see Details for available options).- n
integer
number of colors required. ANULL
argument can also be used to obtain a default number of colors. If aNULL
argument is supplied and the palette has a limited number of colors, then the maximum number of colors is returned. Otherwise, if aNULL
argument is supplied and the palette does not have a limited number of colors, then a 20 colors are returned. The default argument isNULL
.
Details
This function can be used to generate colors using palettes provided by
the RColorBrewer and viridisLite packages. If colors are
from multiple palettes, they can be supplied as a single character
object delimited by semicolon (";"
) characters.
Specifically, available palettes include:
"viridis"
(seeviridisLite::viridis()
)"magma"
(seeviridisLite::magma()
)"plasma"
(seeviridisLite::plasma()
)"inferno"
(seeviridisLite::inferno()
)"cividis"
(seeviridisLite::cividis()
)"mako"
(seeviridisLite::mako()
)"rocket"
(seeviridisLite::rocket()
)"turbo"
(seeviridisLite::turbo()
)"BrBG
" (seeRColorBrewer::brewer.pal()
)"PiYG
" (seeRColorBrewer::brewer.pal()
)"PRGn
" (seeRColorBrewer::brewer.pal()
)"PuOr
" (seeRColorBrewer::brewer.pal()
)"RdBu
" (seeRColorBrewer::brewer.pal()
)"RdGy
" (seeRColorBrewer::brewer.pal()
)"RdYlBu
" (seeRColorBrewer::brewer.pal()
)"RdYlGn
" (seeRColorBrewer::brewer.pal()
)"Spectral
" (seeRColorBrewer::brewer.pal()
)"Accent
" (seeRColorBrewer::brewer.pal()
)"Dark2
" (seeRColorBrewer::brewer.pal()
)"Paired
" (seeRColorBrewer::brewer.pal()
)"Pastel1
" (seeRColorBrewer::brewer.pal()
)"Pastel2
" (seeRColorBrewer::brewer.pal()
)"Set1
" (seeRColorBrewer::brewer.pal()
)"Set2
" (seeRColorBrewer::brewer.pal()
)"Set3
" (seeRColorBrewer::brewer.pal()
)"Blues
" (seeRColorBrewer::brewer.pal()
)"BuGn
" (seeRColorBrewer::brewer.pal()
)"BuPu
" (seeRColorBrewer::brewer.pal()
)"GnBu
" (seeRColorBrewer::brewer.pal()
)"Greens
" (seeRColorBrewer::brewer.pal()
)"Greys
" (seeRColorBrewer::brewer.pal()
)"Oranges
" (seeRColorBrewer::brewer.pal()
)"OrRd
" (seeRColorBrewer::brewer.pal()
)"PuBu
" (seeRColorBrewer::brewer.pal()
)"PuBuGn
" (seeRColorBrewer::brewer.pal()
)"PuRd
" (seeRColorBrewer::brewer.pal()
)"Purples
" (seeRColorBrewer::brewer.pal()
)"RdPu
" (seeRColorBrewer::brewer.pal()
)"Reds
" (seeRColorBrewer::brewer.pal()
)"YlGn
" (seeRColorBrewer::brewer.pal()
)"YlGnBu
" (seeRColorBrewer::brewer.pal()
)"YlOrBr
" (seeRColorBrewer::brewer.pal()
)"YlOrRd
" (seeRColorBrewer::brewer.pal()
)"random"
(the above palettes are randomly used to generate colors)
Examples
# obtain 5 colors from the Greens palette
color_palette("Greens", 5)
#> [1] "#EDF8E9" "#BAE4B3" "#74C476" "#31A354" "#006D2C"
# obtain all colors from the Greens palette
color_palette("Greens", NULL)
#> [1] "#F7FCF5" "#E5F5E0" "#C7E9C0" "#A1D99B" "#74C476" "#41AB5D" "#238B45"
#> [8] "#006D2C" "#00441B"
# obtain 15 colors using the Set1 and Pastel1 palettes
color_palette("Set1;Pastel1", 15)
#> [1] "#E41A1C" "#377EB8" "#4DAF4A" "#984EA3" "#FF7F00" "#FFFF33" "#A65628"
#> [8] "#F781BF" "#999999" "#FBB4AE" "#B3CDE3" "#CCEBC5" "#DECBE4" "#FED9A6"
#> [15] "#FFFFCC"
# obtain all colors from the plasma palette
color_palette("plasma", NULL)
#> [1] "#0D0887FF" "#7E03A8FF" "#CC4678FF" "#F89441FF" "#F0F921FF"
# obtain all colors from a random palette
color_palette("random", NULL)
#> [1] "#543005" "#8C510A" "#BF812D" "#DFC27D" "#F6E8C3" "#F5F5F5" "#C7EAE5"
#> [8] "#80CDC1" "#35978F" "#01665E" "#003C30"
# obtain 5 colors from random palette(s)
color_palette("random", 5)
#> [1] "#FEF0D9" "#FDCC8A" "#FC8D59" "#E34A33" "#B30000"