Skip to content

Placement of words in a word cloud as per its occurance.

3 messages · shaila shailaja, Jim Lemon, Peter Dalgaard

#
Dear R help subscribers,




I am working on a word cloud where in I want the words to appear in the same order as in the sentence/text. 

I only know the random.order - which plots words in random order. If false, they will be plotted in decreasing frequency.

 

Any help is most welcome.

 

Regards

Shailaja
#
Hi Shailaja,
If you just want a line of words, it's not too difficult if you have
the word frequencies:

# take a common sentence
sentence<-"The quick brown fox jumps over the lazy dog"
words<-unlist(strsplit(sentence," "))
# make up some word frequencies
wordfreq<-c(10,1,2,2,3,4,10,6,5)
library(plotrix)
# scale the frequencies into a convenient range
wordcex<-rescale(wordfreq,c(0.5,2))
x11(height=4)
# a simple function to display a vector of words in different sizes
wordline<-function(words,wordcex,space=0.005) {
 plotxy<-par("usr")
 x<-plotxy[1]
 y<-sum(plotxy[3:4])/2
 space<-diff(plotxy[1:2])*space
 for(i in 1:length(words)) {
  par(cex=wordcex[i])
  text(x,y,words[i],adj=0)
  x<-x+strwidth(words[i])+space
 }
}
# get an empty plot
plot(1:10,type="n",axes=FALSE,xlab="",ylab="")
# display the words
wordline(words,wordcex)

The function can be elaborated to fit the sentence into the available
space, break it into lines, all that sort of thing.

Jim


On Tue, May 17, 2016 at 9:09 PM, shaila  shailaja
<shaila_jm at rediffmail.com> wrote:
#
A few points of order; you seem to be making a couple of rookie mistakes here. (Don't take it personally, lots of people do).

1) Posting in HTML comes across garbled (and it can get much worse than what you see below), so please configure you mail program to avoid doing that.

2) You seem to assume that we all immediately recognize the task you are working on and that there is a well-known and generally accepted methodology for which we just need to supply some detail that you have overlooked. In fact, the majority will be doing things in hundreds of different directions, and even those who are into wordclouds may be taking different approaches to it, there could be implementations in several packages, etc. Some people might be mildly interested in helping out (perhaps they want to make a wordcloud for themselves one day), but they would need to know what code you are using. As it stands, people are left wondering which function it might be that has an argument called random.order.

- Peter Dalgaard
On 17 May 2016, at 13:09 , shaila shailaja <shaila_jm at rediffmail.com> wrote: