Folks,
I try to obtain color hex codes from a wesanderson
palette when it is set to continuous with more colors than the predefined numbers of colors.
library('wesanderson')
To obtain all the hex codes of the predefined palettes:
wes_palettes
However, how to obtain the hex codes of the following plot:
wes_palette(21, name = "Zissou1", type = "continuous")
Try unclass
.
> library('wesanderson')
> pal <- wes_palette(21, name = "Zissou1", type = "continuous")
> unclass(pal)
[1] "#3A9AB2" "#54A5B9" "#6FB2C1" "#80B6BB" "#91BAB6" "#9BBDAC" "#A5C2A3" "#B1C492" "#BDC881"
[10] "#CCC967" "#DCCB4E" "#DFC12F" "#E3B710" "#E4A70A" "#E79805" "#E98905" "#EC7A05" "#ED6803"
[19] "#EF5703" "#F03801" "#F11B00"
attr(,"name")
[1] "Zissou1"
Explanation:
pal
, the object returned is of:
> class(pal)
[1] "palette"
and pal
or explicitly print(pal)
will dispatch the print.palette
method that produces a plot.
unclass
strips off additional classes and will leave the base layer class, which is:
> class(unclass(pal))
[1] "character"
and which will dispatch print.default
.
To show color hex codes, we can use text()
:
> pal
> text(x=seq_along(pal), y=.75, labels=pal, srt=90, col='black')