makeColorMatrix: makeColorMatrix

Description Usage Arguments Examples

View source: R/utils-color.R

Description

Transform object to rgb color matrix

Usage

1

Arguments

x

Object representing the color. Can be of class integer, numeric, Date, POSIX*, character with color names or HEX codes, factor, matrix, data.frame, list, json or formula.

data

The dataset

palette

Name of a color palette. If colourvalues is installed, it is passed to colour_values_rgb. To see all available palettes, please use colour_palettes. If colourvalues is not installed, the palette is passed to colorNumeric.

...

Passed to colour_palettes or colorNumeric.

Examples

 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
{
## For Integer/Numeric/Factor
makeColorMatrix(23L)
makeColorMatrix(23)
makeColorMatrix(as.factor(23))

## For POSIXt / Date
makeColorMatrix(as.POSIXlt(Sys.time(), "America/New_York"), NULL)
makeColorMatrix(Sys.time(), NULL)
makeColorMatrix(Sys.Date(), NULL)

## For matrix/data.frame
makeColorMatrix(cbind(130,1,1), NULL)
makeColorMatrix(matrix(1:99, ncol = 3, byrow = TRUE), data.frame(x=c(1:33)))
makeColorMatrix(data.frame(matrix(1:99, ncol = 3, byrow = TRUE)), data.frame(x=c(1:33)))

## For characters
library(leaflet)
makeColorMatrix("red", breweries91)
makeColorMatrix("blue", breweries91)
makeColorMatrix("#36ba01", breweries91)
makeColorMatrix("founded", data.frame(breweries91))

## For formulaes
makeColorMatrix(~founded, breweries91)
makeColorMatrix(~founded + zipcode, breweries91)

## For JSON
library(jsonify)
makeColorMatrix(jsonify::to_json(data.frame(r = 54, g = 186, b = 1)), NULL)

## For Lists
makeColorMatrix(list(1,2), data.frame(x=c(1,2)))
}

Example output

Loading required package: sp
          [,1]        [,2]      [,3]
[1,] 0.2666667 0.003921569 0.3294118
[2,] 0.9921569 0.905882353 0.1450980

leafgl documentation built on July 2, 2020, 4:02 a.m.