-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSentiment Analysis.Rmd
executable file
·54 lines (44 loc) · 1.81 KB
/
Sentiment Analysis.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---
title: "Sentiment Analysis"
output:
word_document: default
html_document: default
pdf_document: default
---
# Ref - https://cran.r-project.org/web/packages/syuzhet/vignettes/syuzhet-vignette.html
# https://github.com/DevikaMishra-Dataturks/Twitter_Data_Analysis
# https://hackernoon.com/text-processing-and-sentiment-analysis-of-twitter-data-22ff5e51e14c
```{r imports}
if (!require(syuzhet)) {install.packages("syuzhet")}
if (!require(ggplot2)) {install.packages("ggplot2")}
if (!require(matrixStats)) {install.packages("matrixStats")}
```
```{r}
swiggy = readLines('data/swiggy.txt')
sentiment <- get_nrc_sentiment((swiggy))
sentiment_scores <- data.frame(colMeans(sentiment[,]))
names(sentiment_scores) <- "Score"
sentiment_scores <- cbind("sentiment" = rownames(sentiment_scores), sentiment_scores)
rownames(sentiment_scores) <- NULL
#plotting the sentiments with scores
ggplot(data=sentiment_scores, aes(x=sentiment, y=Score)) +
geom_bar(aes(fill=sentiment), stat = "identity") +
theme(legend.position = "none")+
ylim(0,1.2) +
xlab("Sentiment Type") + ylab("Mean sentiment score") + ggtitle("Sentiments of people tweeting to Swiggy handle")
```
```{r}
zomato = readLines('data/zomato.txt')
sentiment <- get_nrc_sentiment((zomato))
sentiment_scores <- data.frame(colMeans(sentiment[,]))
#sentiment_scores <- data.frame(colSums(sentiment[,]))
names(sentiment_scores) <- "Score"
sentiment_scores <- cbind("sentiment" = rownames(sentiment_scores), sentiment_scores)
rownames(sentiment_scores) <- NULL
#plotting the sentiments with scores
ggplot(data=sentiment_scores, aes(x=sentiment, y=Score)) +
geom_bar(aes(fill=sentiment), stat = "identity") +
theme(legend.position = "none")+
ylim(0,1.2) +
xlab("Sentiment Type") + ylab("Mean sentiment score") + ggtitle("Sentiments of people tweeting to Zomato handle")
```