Sentimental Analysis in Tableau using R

Sentimental Analysis in Tableau using R

We all know R can be pretty handy in dealing with sentimental analysis and text mining. But nowadays visualization is one of the part of analysis different clients, vendors are more comfortable with. As we all know Tableau and R can be integrated so I tried to use Tableau to work on Sentimental analysis with the help of R. Bora Beran article has been a great help. I used command from 2 different packages of R an integrated in Tableau. You can follow my steps to build a sentimental analysis dashboard in Tableau too.

Step 1 : Install packages tm, Rserve,sentiment, tm,installr,Rstem,syuzhet and plyr.

Sentiment package is not available in now so you need to download the package outside of cran. installr and Rstem need to be installed as dependencies of sentiment. Plyr package is downloaded for the function count which we will use in our analysis. Rserve needs to be there because it helps to connect with tableau. To download sentiment package use this :

install.packages("devtools")

library(devtools)

install_github("aloth/sentiment/sentiment")

library(sentiment)

The code in R console should look like this:

Now go to the tableau and load your text file and then open the connection with R. here is the way to open the connection.

Go to help>settings and performance >manage external service connection. then follow the next step.

click the test connection and if you are connected then it will show its connected.Click ok. So now if you are connected lets start our analysis.

Load the data in tableau and create calculated fields. I need a sentiment score, a sentiment status and emotions. so I created 3 calculated fields.

For Sentiment score the calculated field code :

SCRIPT_REAL('library(syuzhet);

len <- length(.arg1);

result<-numeric(len);

for (i in 1:len){

token <- get_tokens(.arg1[i]);

sentiment <- get_sentiment(token,method = "syuzhet")

sentiment <- sentiment[sentiment!=0]

result[i]<-mean(sentiment)

}

result',

ATTR([your text body]))

For the sentiment status as negative , positive and neutral use the code :

SCRIPT_STR(

"

library(sentiment);

classify_polarity(.arg1,algorithm='bayes',verbose=TRUE)[,4]",

ATTR([your text body])

)

For emotions :

SCRIPT_STR(

"

library(sentiment);

classify_emotion(.arg1,algorithm='bayes',verbose=TRUE)[,7]",

ATTR([your text body])

)

classify_emotion and classify_polarity comes from the sentiment package. classify_emotion:::Classifies the emotion (e.g. anger, disgust, fear, joy, sadness, surprise) of a set of texts using a naive Bayes classifier trained on Carlo Strapparava and Alessandro Valitutti's emotions lexicon. classify_polarity::Classifies the polarity (e.g. positive or negative) of a set of texts using a naive Bayes classifier trained on Janyce Wiebe's subjectivity lexicon.

your tableau workbook should look like this

Now it upto to you how you want to present in your dashboard and graphs.

thank you.


Learn tableau at your own ease and pace with the help of best tableau courses. https://www.takethiscourse.net/tableau-training-certification-courses/

Like
Reply

Great article, any update on the link to download the library(sentiment) package?

library(sentiment) is no longer valid, please suggest some alternative code in library(syuzhet) to get similar results

Like
Reply

To view or add a comment, sign in

More articles by Tirthankar Goon

Others also viewed

Explore content categories