3

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?

Bartli
  • 315
  • 2
  • 11
  • 1
    Have a look of [**this question**](https://stackoverflow.com/questions/43894416/wordcloud-showing-colour-based-on-continous-metadata-in-r). I think this will help you. – jazzurro Feb 08 '18 at 13:30

2 Answers2

4

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))
G5W
  • 36,531
  • 10
  • 47
  • 80
1

Probably HTML color codes are meant by "numbered colors", e.g.

wordcloud2(demoFreq, color= "#0080CC")

When "blue1" is not defined anywhere wordcloud2() has no color to use. But you could define one yourself.

library(wordcloud2)
blue1 <- "#0080CC"
wordcloud2(demoFreq, color= blue1)

Note that there are no quotes "" in this case.

There are more color names available here. The package itself defines 'random-dark' and 'random-light' in addition.

Edit: According to @GW5's comment use following code to obtain exactly the desired "blue1"as a workaround:

blue1 <- colors()[27]
wordcloud2(demoFreq, color= blue1)
jay.sf
  • 60,139
  • 8
  • 53
  • 110