rcolorswordcloud2

wordcloud2 does not display numbered colors


When I use numbered colors in wordcloud2, nothing is displayed.

library(wordcloud2)
wordcloud2(demoFreq,color='blue1')

Color names without numbers are ok. E.g. color='blue'

What am I missing?


Solution

  • Since the word cloud is being rendered in HTML, you need to use html colors. blue1 is an R color, not HTML, so you need to convert it to a hex value color. the R function col2rgb will give an RGB triple, but that will not work with HTML. You need to convert the triple to a hex value. You can do that using rgb. However, rgb expects 3 columns, not a column of 3 values, so use t to transpose the RGB values.

    rgb(t(col2rgb("blue1")),  maxColorValue = 255)
    [1] "#0000FF"
    

    Now you can successfully call wordcloud2

    wordcloud2(demoFreq, color=rgb(t(col2rgb("blue1")), maxColorValue = 255))