-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSentimentAnalysis.R
More file actions
33 lines (27 loc) · 917 Bytes
/
SentimentAnalysis.R
File metadata and controls
33 lines (27 loc) · 917 Bytes
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
library(syuzhet)
setwd("C:/Users/julio/Dropbox/PC/Desktop/Books/")
ratings <- data.table::fread("reviews_data_modified.csv")
#First 1000 reviews for testing
reviews <- ratings$`Review/Text`[1:100001]
sentiment = get_nrc_sentiment(reviews)
td = data.frame(t(sentiment))
td[,1:5]
td = data.frame(rowSums(td[-1]))
td
names(td)[1] <- "count"
td
tdw <- cbind("sentiment" = rownames(td), td)
tdw
rownames(tdw) <- NULL
tdw
td_em = tdw[1:8, ] # emotions
td_pol = tdw[9:10, ] # polarity
require("ggplot2")
ggplot(td_em, aes(x = sentiment, y = count, fill = sentiment)) +
geom_bar(stat = "identity") +
labs(x = "emotion") +
theme(axis.text.x=element_text(angle=45, hjust=1), legend.title = element_blank())
ggplot(td_pol, aes(x = sentiment, y = count, fill = sentiment)) +
geom_bar(stat = "identity") +
labs(x = "polarity") +
theme(axis.text.x=element_text(angle=45, hjust=1), legend.title = element_blank())