1

Is it possible to highlight single words within a word cloud using 'wordcloud' or 'wordcloud2'? Does one have to add another column to the data frame as ordering factor?

I couldn't find any simple solution.

Here's what I've done:

wordcloud(text_process$words[1:n.words],
          text_process$frequency[1:n.words],
          scale = c(18, 0.5),
          colors = c("#666666", "#3E6AA0") [factor(text_process$matches[1:n.words])],
          use.r.layout = FALSE,
          rot.per = 0.2,
          random.order = FALSE, ordered.colors=TRUE)

I had to introduce a criterion (called 'matches') in the data frame 'text_process' that indicates the color. I was wondering whether there's a simpler way of highlighting specific words...

  • 2
    It would be easier to help you if you provided a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with some sample data and the code you are using to make a plot. Then we can test possible solutions. – MrFlick Sep 20 '17 at 14:34

1 Answers1

1
# Not Tested
library(randomcoloR)

cols<-randomColor(length(unique(test_process$words[1:n.words])), luminosity = "dark")

match_value<-match("HighlightThisWord", test_process$words[1:n.words])

cols[match_value]<-"orange"

wordcloud(text_process$words[1:n.words],
      text_process$frequency[1:n.words],
      scale = c(18, 0.5),
      colors = cols,
      use.r.layout = FALSE,
      rot.per = 0.2,
      random.order = FALSE, ordered.colors=TRUE)
user3466328
  • 398
  • 1
  • 11