Learn R Programming

qdap (version 0.2.5)

text2color: Map Words to Colors

Description

A dictionary lookup that maps words to colors.

Usage

text2color(words, recode.words, colors)

Arguments

words
A vector of words.
recode.words
A vector of unique words or a list of unique word vectors that will be matched against corresponding colors.
colors
A vector of colors of equal in length to recode.words + 1(the +1 is for unmatched words).

Value

  • Returns a vector of mapped colors equal in length to the words vector.

See Also

lookup

Examples

Run this code
set.seed(10)
x <- data.frame(X1 = sample(Top25Words[1:10], 20, TRUE))

#blue was recycled
text2color(x$X1, qcv(the, and, is), qcv(red, green, blue))
text2color(x$X1, qcv(the, and, is), qcv(red, green, blue, white))
x$X2 <- text2color(x$X1, list(qcv(the, and, is), "that"),
    qcv(red, green, white))
x

Run the code above in your browser using DataLab