Skip to Content
Technical Articles

Word Cloud of Word Frequency in SAP Analytics Cloud along with Data Cleaning

R Visualization is generally being used to create those charts which are not directly available in SAP Analytics Cloud. In this blog I am going to explain how to clean the data and create Word Cloud of Word Frequency in SAP Analytics Cloud using R Visualization.

Below are the steps being used to clean the data and create a word cloud in SAP Analytics Cloud using R Visualization:

 

Step-1: Either create a new Story or open an existing story in edit mode. Navigate to “Insert” and click on “+” button. Click on “R Visualization”.

 

Step-2: Add the Model along with dimensions in rows as Input Data in Builder.

 

Step-3: Click on “Add Script” in Builder.

 

Step-4: Expand the window.

 

Step-5: There are 4 panes in the window i.e. Editor, Environment, Console and Preview. Write R code in Editor. After that execute the code by clicking on “Execute” button. If there is no error message in Console and word cloud is being displayed in Preview, then click on “Apply” button.

 

R Code:

library(ggplot2)

library(tm)

library(SnowballC)

library(wordcloud)

library(RColorBrewer)

set.seed(123)

text <- Data$Comments

TextDoc <- Corpus(VectorSource(text))

 

toSpace <- content_transformer(function (x , pattern ) gsub(pattern, ” “, x))

TextDoc <- tm_map(TextDoc, toSpace, “/”)

 

TextDoc <- tm_map(TextDoc, toSpace, “@”)

 

TextDoc <- tm_map(TextDoc, toSpace, “\\|”)

 

TextDoc <- tm_map(TextDoc, content_transformer(tolower))

 

TextDoc <- tm_map(TextDoc, removeNumbers)

 

TextDoc <- tm_map(TextDoc, removeWords, stopwords(“english”))

 

TextDoc <- tm_map(TextDoc, removePunctuation)

 

TextDoc <- tm_map(TextDoc, stripWhitespace)

 

TextDoc <- tm_map(TextDoc, stemDocument)

 

TextDoc_dtm <- TermDocumentMatrix(TextDoc)

dtm_m <- as.matrix(TextDoc_dtm)

dtm_v <- sort(rowSums(dtm_m),decreasing=TRUE)

dtm_d <- data.frame(word = names(dtm_v),freq=dtm_v)

head(dtm_d, 5)

wordcloud(words = dtm_d$word, freq = dtm_d$freq, scale = c(6,1), min.freq = 5,

max.words=100, random.order=FALSE, rot.per=0.40,

colors=brewer.pal(8, “Dark2”))

 

 

Step-6: The word cloud is being displayed in the story.

 

In this way we can clean the data and create a word cloud in SAP Analytics Cloud using R Visualization.

 

Conclusion: R Visualization is the very powerful feature of SAP Analytics Cloud where we can do coding using R. Using R Visualization feature we can clean the data and create a word cloud in SAP Analytics Cloud.

Technical inputs shared by @Bhanu Bisht

 

Be the first to leave a comment
You must be Logged on to comment or reply to a post.