Description Usage Arguments Details Value Allowed colour Formats colour types colour checks colour conversion inverse.colour Author(s) Examples
A collection of functions to convert colours from names
(aka colours
), hex values (aka hex
) and RGB
3 character numeric's (aka rgb
). This is
old code, and is crying out for at least some
S3-class love. It was written to facilitate the
interpolation of lots of colours, which requires named
colours to be numerically represented. This code allows
colour.step
to do its thing, though newer
code in the RColorBrewer
package may make much of
this redundant.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | colours.hex()
colours.rgb()
is.colour(col)
is.hex.colour(hex)
is.rgb.colour(rgb)
colour2rgb(col = NULL)
colour2hex(col = NULL)
hex2rgb(hex = NULL)
rgb2hex(rgb)
hex2colour(hex, cols.rgb = colours.rgb())
rgb2colour(rgb, cols.rgb = colours.rgb())
inverse.colour(col)
|
col |
a vector of values in the |
rgb |
a vector of colours in the |
hex |
a vector of colours in the hex format: eg “#FF00FF” |
cols.rgb |
the pool of colours with which to map
|
grDevices provides colours
, and
col2rgb
. We wanted a hexadecimal
representation of colours which included an alpha
channel, as well as methods for checking colours,
converting between colour types, and generating a
spectrum of colours.
colours
, colours.hex
, colours.rgb
: a
vector of col-format colours, hex-format colours, or
matrix of rgb-format colours, 1 row per colour.
is.colour
, is.hex.colour
,
is.rgb.colour
: logical.
colour2rgb
,
colour2hex
, hex2rgb
, rgb2hex
,
hex2colour
, rgb2colour
: a vector of colour
formats, converted from one to another.
hex2colour
: a vector of the name of R colours; eg
c("white", "magenta", "lightblue")
or a vector of
indices into the cols.rgb
vector, if no valid
names were found in the cols.rgb
object.
rgb2colour
: a vector of the name of R colours; eg
c("white", "magenta", "lightblue")
, or a vector of
indices into the cols.rgb
vector, if no valid
names were found in the cols.rgb
object.
inverse.colour
: a vector of colours
We've named the default colours provided by grDevices the
col
format, for want of a better name.
col:"White", "white", "Black", "green"
hex:"#FF00FF", "#FF00FFAE"
rgb:matrix(c(0,255,0), 1, 3)
colours
, colours.hex
, colours.rgb
:
return the hex, or rgb representations of the named
colours provided by colours
from
grDevices
.
is.colour
, is.hex.colour
,
is.rgb.colour
: methods for checking whether the
input is one of the 3 colour types, the hex colour type,
or rgb colour type, respectively.
colour2rgb
, colour2hex
: convert from
col
format
hex2rgb
, hex2colour
:
convert from hex format
rgb2hex
,
rgb2colour
: convert from rgb format
Note,
hex2colour
: there are 256^3 possible hex's but
only length(colours())
possible outputs, so the
closest colour for each hex
is determined. This
function is the opposite of grDevices:col2rgb
, and
also is the opposite of colour2rgb
Note,
rgb2colour
: there are 256^3 possible x's but only
length(cols.rgb()) possible outputs, so the closest
colour for each x is determined. This function is the
opposite of grDevices:col2rgb, and also is the opposite
of colour2rgb
inverse.colour
inverse a col
-format colour & return the
hex
-format colour
Mark Cowley, 29/3/07
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | colours()[1:5]
# [1] "white" "aliceblue" "antiquewhite" "antiquewhite1"
# [5] "antiquewhite2"
colours.hex()[1:5]
# white aliceblue antiquewhite antiquewhite1 antiquewhite2
# "#FFFFFF" "#F0F8FF" "#FAEBD7" "#FFEFDB" "#EEDFCC"
colours.rgb()[1:5,]
# red green blue
# white 255 255 255
# aliceblue 240 248 255
# antiquewhite 250 235 215
# antiquewhite1 255 239 219
# antiquewhite2 238 223 204
is.colour("white") # TRUE
is.colour("#FFFFFF") # FALSE
is.colour(c(255,255,255)) # FALSE
is.hex.colour("white") # FALSE
is.hex.colour("#FFFFFF") # TRUE
is.hex.colour(c(255,255,255)) # FALSE
is.rgb.colour("white") # FALSE
is.rgb.colour("#FFFFFF") # FALSE
is.rgb.colour(c(255,255,255)) # TRUE
colour2rgb("White")
# red green blue
# White 255 255 255
colour2hex("White")
# White
# "#FFFFFF"
hex2rgb( "#FF00E0" )
# red green blue
# [1,] 255 0 224
rgb2hex( matrix(c(255,128,255),1,3) )
# [1] #FF80FF
hex2colour( "#FF80FF" )
# [1] "orchid1"
rgb2colour(matrix(c(255,128,255), 1, 3))
# [1] "orchid1"
inverse.colour("red")
# red
# "#00FFFF"
inverse.colour("orchid1")
# orchid1
# "#007C05"
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.