text2color | R Documentation |
A dictionary lookup that maps words to colors.
text2color(words, recode.words, colors)
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). |
Returns a vector of mapped colors equal in length to the words vector.
lookup
x <- structure(list(X1 = structure(c(3L, 1L, 8L, 4L, 7L, 2L, 2L, 2L,
4L, 8L, 4L, 3L, 5L, 3L, 1L, 8L, 7L, 2L, 1L, 6L), .Label = c("a",
"and", "in", "is", "of", "that", "the", "to"), class = "factor")),
.Names = "X1", row.names = c(NA, -20L), class = "data.frame")
#blue was recycled
text2color(x$X1, c("the", "and", "is"), c("red", "green", "blue"))
text2color(x$X1, c("the", "and", "is"), c("red", "green", "blue", "white"))
x$X2 <- text2color(x$X1, list(c("the", "and", "is"), "that"),
c("red", "green", "white"))
x
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.