Colours in R are internally encoded as integers when they are passed around
to graphics devices. The encoding splits the 32 bit in the integer between
red, green, blue, and alpha, so that each get 8 bit, equivalent to 256
values. It is very seldom that an R user is subjected to this representation,
but it is present in the
nativeRaster format which can be obtained from
e.g. capturing the content of a graphic device (using
dev.cap()) or reading
in PNG files using
png::readPNG(native = TRUE). It is very rare that you
might need to convert back and forth between this format, but it is provided
here for completeness.
encode_native(colour, ...) decode_native(colour)
Arguments passed on to
encode_native() returns an integer vector and
returns a character vector, both matching the length of the input.
# Get native representation of navyblue and #228B22 native_col <- encode_native(c('navyblue', '#228B22')) native_col # Convert back decode_native(native_col)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.