0
votes

I'm trying to change the size of a wordcloud but I don't know how to do this. Apparently lower values of fig.width make the plot bigger, not smaller, and vice versa. It seems to take up an enormous amount of space, compared to the second plot which is just the right size.

\documentclass{report}

\begin{document}

<<echo=FALSE,message=FALSE,warning=FALSE,fig.width=3>>=
library(wordcloud)
set.seed(1)
freq<-sample(letters,2000,prob=1:26,rep=T)

wordcloud(names(table(freq)),table(freq),min.freq=60,colors=brewer.pal(6,"Dark2"),scale=c(1,.2))
@

<<echo=FALSE,warning=FALSE>>=
library(ggplot2)

freq<-table(freq)

wf<-as.data.frame(freq)
wf$freq<-ordered(wf$freq,levels=wf$freq[order(wf$Freq)])

ggplot(subset(wf,Freq>60),aes(freq,Freq)) +
  geom_bar(stat="identity") +
  theme(axis.text.x=element_text(angle=45,hjust=1))
@

\end{document}
1

1 Answers

2
votes

The arguments fig.width & fig.height provide aspect-ratio between the two axis: in order to indicate the size of the plot in your knitted / exported document, you should use both of them, ever (e.g., by using pandoc when knitting a rmarkdown file to a .docx).

Alternatively, the fig.asp = let you adjust the size of the image (e.g., multiply current size by 2 with fig.asp = 2). However, this method still provides a fig.height and fig.width parameters during the export (under the hood).