Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can one increase size of plotted area wordclouds in R

trying to replicate the example here;

http://onertipaday.blogspot.com/2011/07/word-cloud-in-r.html

Need help figuring out how to increase the plotted area of the word cloud. Changing the height and width parmeters in png("wordcloud_packages.png", width=1280,height=800) only changes the height and width of the canvas..but the plotted area remains small.

require(XML)
require(tm)
require(wordcloud)
require(RColorBrewer)
u = "http://cran.r-project.org/web/packages/available_packages_by_date.html"
t = readHTMLTable(u)[[1]]
ap.corpus <- Corpus(DataframeSource(data.frame(as.character(t[,3]))))
ap.corpus <- tm_map(ap.corpus, removePunctuation)
ap.corpus <- tm_map(ap.corpus, tolower)
ap.corpus <- tm_map(ap.corpus, function(x) removeWords(x, stopwords("english")))
ap.tdm <- TermDocumentMatrix(ap.corpus)
ap.m <- as.matrix(ap.tdm)
ap.v <- sort(rowSums(ap.m),decreasing=TRUE)
ap.d <- data.frame(word = names(ap.v),freq=ap.v)
table(ap.d$freq)
pal2 <- brewer.pal(8,"Dark2")
png("wordcloud_packages.png", width=1280,height=800)
wordcloud(ap.d$word,ap.d$freq, scale=c(8,.2),min.freq=3,
max.words=Inf, random.order=FALSE, rot.per=.15, colors=pal2)
dev.off()
like image 571
sgt pepper Avatar asked Feb 12 '12 00:02

sgt pepper


People also ask

How do I increase the size of word cloud in R?

If you include par(mar = rep(0, 4)) as a separate line immediately after the call to png you'll remove the margins, and the wordcloud will use all the available space. With this, and possibly tweaking the res parameter as suggested in the previous answer, you should get what you wanted.

What is wordcloud package in R?

A wordcloud (or tag cloud) is a visual representation of text data. Tags are usually single words, and the importance of each tag is shown with font size or color. In R , two packages allow to create wordclouds: Wordcloud and Wordcloud2 . Wordcloud2.

Could not be fit on page it will not be plotted wordcloud?

Try adjusting the scale option scale=c(4, . 5) in the wordcloud function, using a max size smaller than 4 may allow the words to fit on the page.


2 Answers

Try using the res parameter, instead:

...
png("wordcloud_packages.png", width=12,height=8, units='in', res=300)
...

enter image description here

like image 68
John Colby Avatar answered Oct 08 '22 07:10

John Colby


If you include par(mar = rep(0, 4)) as a separate line immediately after the call to png you'll remove the margins, and the wordcloud will use all the available space. With this, and possibly tweaking the res parameter as suggested in the previous answer, you should get what you wanted.

like image 28
giocomai Avatar answered Oct 08 '22 06:10

giocomai