As an example, I chose to work with the speeches given by US Presidents at the United Nations General Assembly. The following line of code shows you how to properly set the arguments. The wordcloud package is the most classic way to generate a word cloud. install.packages("tm") library(tm) #Create a vector containing only the text text % tm_map(removeNumbers) %>% tm_map(removePunctuation) %>% tm_map(stripWhitespace) docs % select(text) %>% unnest_tokens(word, text) words % count(word, sort=TRUE) STEP 4: Generate the word cloud A useful way to do this is to use the tm package. If you’re working on a speech, article or any other type of text, make sure to load your text data as a corpus. If you’re analysing twitter data, simply upload your data by using the rtweet package (see this article for more info on this). Most often, word clouds are used to analyse twitter data or a corpus of text. install.packages("wordcloud") library(wordcloud) install.packages("RColorBrewer") library(RColorBrewer) install.packages("wordcloud2) library(wordcloud2) I will show you how to use both packages. Note that there is also a wordcloud2 package, with a slightly different design and fun applications. To generate word clouds, you need to download the wordcloud package in R as well as the RcolorBrewer package for the colours. STEP 1: Retrieving the data and uploading the packages In the following section, I show you 4 simple steps to follow if you want to generate a word cloud with R.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |