Text Analytics: Keywords Extraction And Visualisation | R programming

Objective: To Analyse and visualize a short story through keyword extraction 


Step 1: Download text file of short story from HERE

Step 2: Read file in R
>Textualdata <- scan(file = "/Users/planetanalytics/Desktop/31pigs.txt", what = "character", sep = "\n")

Step 3: Install and load required packages
>library(tm)
>library(qdap)
>library(wordcloud)
>library(RColorBrewer)

Step 4: Clean your textual data

>Cleandata <- removePunctuation(Textualdata)
>Cleandata <- removeNumbers(Cleandata)
>Cleandata <- removeWords(Cleandata, c("pigs", "pig", stopwords(kind = "english")))

Step 5: Find the most frequent words and make a dataset

TextFrequency <- freq_terms(Cleandata, at.least = 3, stopwords = stopwords)

Step 6: Visualise

>plot(TextFrequency)

Output:


Plot a wordcloud

>TextWordcloud <- wordcloud(TextFrequency$WORD, TextFrequency$FREQ, colors = brewer.pal(3, "Dark2"))

 

Thanks for visiting Planet Analytics, Connect with us at info@planetanalytics.in