Creating word clouds with the wordcloud package
Word clouds are a nice and useful way to show text composition at a glance.
In a word cloud, words composing a text are composed in a kind of cloud, and usually their size and color is related to the frequency of the given term in the source text.
In this way, it is possible to understand quickly which words are more relevant to the given text. In this recipe, we will explore the Wikipedia page related to the R programming language.
Getting ready
We first need to install the required packages and load them into the R environment:
install.packages(c("wordcloud","RColorBrewer","rvest")) library(wordcloud) library(rvest) library(RColorBrewer)
How to do it...
Define your document URL and download it in the R environment:
url <- "https://en.wikipedia.org/wiki/R_(programming_language)" page <- read_html(url) page <- html_text(page,trim = TRUE) page <- gsub("\n","",page, fixed = FALSE) page <- gsub("\t","",page, fixed = FALSE)
Print out...