cancel
Showing results for 
Search instead for 
Did you mean: 

Formatting a word cloud in SAC.

0 Kudos
530

I have created a beautiful word cloud in SAC (impressed with myself as total newbie to R). Thank you to the contributors who assisted me in my endeavours.

However, the word cloud consumes a great deal of screen real estate. I can shrink the size of the widget, however, that also reduces the size of the content. Could I please have advice (relevant script) on how I can format the word cloud so that it fills the word cloud container.

I would also like more control over the colours assigned to the words (based on frequency, or proportion, or ranking of the measure). For example:

  • if rank is 1, 2, 3 then the words should be colour x,
  • if rank is 4-6, then the words should be colour y, etc
  • and if rank is > 20 then colour

In addition, is there a limit to the length of words/phrases that can be displayed in a word cloud? I have created another word cloud with phrases. Unfortunately, some of the phrases are being truncated.

I look forward to your good advice. Marea

I've included the code use to create the following word cloud;

#Code to show a wordcloud
library(wordcloud)
library(RColorBrewer)

#Attach the dataset
attach(Opportunities)

#Get Words
Opportunities$'Industry Type'=gsub(paste0('Totals',collapse='|'),"",Opportunities$'Industry Type')
#Opportunities$'Industry Type'=gsub(paste0('Not assigned',collapse='|'),"",Opportunities$'Industry Type')
#Opportunities$'Industry Type'=gsub(paste0('Aust. SME',collapse='|'),"",Opportunities$'Industry Type')
words <-Opportunities$'Industry Type'

#Get Frequency 
frequency <-Opportunities$'Count'

#Create the wordcloud
wordcloud(words,frequency, scale=c(5, 1), min.freq=1, max.words=30, random.color=TRUE, random.order=FALSE, rot.per=0.0, colors=brewer.pal(8,"Dark2"))

Accepted Solutions (0)

Answers (1)

Answers (1)

N1kh1l
Active Contributor

Hello Marea,

Try the below code, this will assign color based on frequency. If you want to color on rank, you need to have a rank column in your data frame and change factor to rank instead of frequency.

wordcloud(words,frequency, scale=c(5, 1), min.freq=1, max.words=30, random.order=FALSE, rot.per=0.0, ordered.colors=TRUE, colors=brewer.pal(8,"Dark2")[factor(frequency)])
0 Kudos

Thanks Nikhil When I added ordered.colours= TRUE - I received an error message "Length of colors does not match length of words vector"

I'm note sure why?

Thanks Marea