as.color: Transform vector of values into color specification

Description Usage Arguments Details Value Examples

View source: R/misc.R

Description

Convenience function to convert a vector of values into a color specification.

Usage

1
2
as.color(x, opacity = 1)
is.color(x)

Arguments

x

vector of numeric, character or factor values to be transformed

opacity

optional numeric value in the range 0.0 to 1.0 used to specify the opacity/transparency (alpha) of the colors to be returned. 0 means fully opaque, 1 means fully transparent.

Details

Behavior of as.color is as follows:

The optional opacity parameter can be used to make colors partially transparent (as a shortcut for adjustcolor. If used, colors will be returned as hex rgb color string (i.e. "#00FF0080")

The is.color function checks if each character element of x appears to be a color name by comparing it to colors and checking if it is an HTML-style hex color code. Note that it will return FALSE for integer values.

These functions are used for the color parameters of plot.network.

Value

For as.color, a vector integer values (corresponding to color palette values) or character color name. For is.color, a logical vector indicating if each element of x appears to be a color

Examples

1
2
3
4
5
6
7
as.color(1:3)
as.color(c('a','b','c'))

# add some transparency
as.color(c('red','green','blue'),0.5) # gives "#FF000080", "#00FF0080", "#0000FF80"

is.color(c('red',1,'foo',NA,'#FFFFFF55'))

network documentation built on May 30, 2017, 6:47 a.m.

Search within the network package
Search all R packages, documentation and source code