This is the most basic barplot you can build with the
wordcloud2 library, using its
wordcloud2() function. Note:
datais a data frame including word and freq in each column
sizeis the font size, default is 1.
It is possible to change the word color using the
color argument. You can provide a vector of color, or use
random-light. You can also customize the background color with
# library library(wordcloud2) # Gives a proposed palette wordcloud2(demoFreq, size=1.6, color='random-dark') # or a vector of colors. vector must be same length than input data wordcloud2(demoFreq, size=1.6, color=rep_len( c("green","blue"), nrow(demoFreq) ) ) # Change the background color wordcloud2(demoFreq, size=1.6, color='random-light', backgroundColor="black")
You can custom the wordcloud shape using the
shape argument. Available shapes are:
You can also use an image like this one as a mask.
Rotate words with 3 arguments:
Chinese version. Comes from the doc.
letterCloud function allows to use a letter or a word as a mask for the wordcloud:
Wordcloud2 is a html widget. It means your wordcloud will be output in a
You can export it as a
png image using rstudio, or using the
webshot library as follow:
# load wordcloud2 library(wordcloud2) # install webshot library(webshot) webshot::install_phantomjs() # Make the graph my_graph <- wordcloud2(demoFreq, size=1.5) # save it in html library("htmlwidgets") saveWidget(my_graph,"tmp.html",selfcontained = F) # and in png or pdf webshot("tmp.html","fig_1.pdf", delay =5, vwidth = 480, vheight=480)