Is there a way to get the name or code for the colours in Set3 colour palette of ggplot2?
CodePudding user response:
You could use brewer.pal
from RColorBrewer
like this:
library(RColorBrewer)
brewer.pal(12, "Set3")
#> [1] "#8DD3C7" "#FFFFB3" "#BEBADA" "#FB8072" "#80B1D3" "#FDB462" "#B3DE69"
#> [8] "#FCCDE5" "#D9D9D9" "#BC80BD" "#CCEBC5" "#FFED6F"
Created on 2022-10-19 with reprex v2.0.2
To get the names of the colors codes, you could use the function color.id
from plotrix
like this:
library(RColorBrewer)
colors <- brewer.pal(12, "Set3")
library(plotrix)
sapply(colors, color.id)
#> $`#8DD3C7`
#> [1] "paleturquoise3"
#>
#> $`#FFFFB3`
#> [1] "wheat1"
#>
#> $`#BEBADA`
#> [1] "lightsteelblue"
#>
#> $`#FB8072`
#> [1] "salmon"
#>
#> $`#80B1D3`
#> [1] "lightskyblue3"
#>
#> $`#FDB462`
#> [1] "sandybrown"
#>
#> $`#B3DE69`
#> [1] "darkolivegreen2"
#>
#> $`#FCCDE5`
#> [1] "thistle2"
#>
#> $`#D9D9D9`
#> [1] "gray85" "grey85"
#>
#> $`#BC80BD`
#> [1] "orchid3"
#>
#> $`#CCEBC5`
#> [1] "darkseagreen1"
#>
#> $`#FFED6F`
#> [1] "lightgoldenrod1"
Created on 2022-10-19 with reprex v2.0.2
CodePudding user response:
Absolutely! These palettes come from ‘RColorBrewer’ and, using that package, you can get the color values from each palette via the following code:
palette = 'Set3'
brewer.pal(brewer.pal.info[palette, 'maxcolors'], palette)