Repository navigation
Expand file tree
/
Copy pathSentiment.R
More file actions
84 lines (68 loc) · 2.43 KB
/
Copy pathSentiment.R
File metadata and controls
84 lines (68 loc) · 2.43 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
read_feather("corpus/Trump_Corpus.feather")
read_feather("corpus/Clinton_Corpus.feather")
read_feather("corpus/Sanders_Corpus.feather")
read_feather("corpus/Repub_Corpus.feather")
speech_corpus <- bind_rows(Trump_Corpus, Clinton_Corpus, Sanders_Corpus, Repub_Corpus)
#Inserting Sentiment
speech_corpus_bing <- speech_corpus %>%
inner_join(get_sentiments("bing"))
#83936 - 10608 = number of words discarded
speech_corpus_affin <- speech_corpus %>%
inner_join(get_sentiments("afinn"))
#83936 - 11562 = number of words we discarded
speech_corpus_nrc <- speech_corpus %>%
inner_join(get_sentiments("nrc"))
#83936 - 43920 = number of words we discarded
speech_corpus_bing %>%
count(author, sentiment) %>%
mutate(percent= n/sum(n))%>%
print()%>%
ggplot(aes(author, percent, fill= author)) +
geom_bar(alpha = .75, stat = "identity", width = .5 )+
facet_grid(~sentiment)+
labs(x= "Speaker",
y= "Percentage of Text") +
coord_flip()
speech_corpus_nrc %>%
count(author, sentiment) %>%
mutate(percent = n/sum(n)) %>%
print()%>%
ggplot(aes(sentiment, percent, fill= sentiment)) +
geom_bar(alpha = .8, stat = "identity")+
facet_wrap(~author) +
coord_flip()
speech_corpus_nrc %>%
count(author, sentiment) %>%
mutate(percent= n/sum(n)) %>%
ggplot(aes(sentiment, percent)) +
geom_freqpoly(aes(color= author, group= author), stat = "identity")
speech_corpus_nrc %>%
count(sentiment, author) %>%
group_by(sentiment) %>%
mutate(percent = n/sum(n)) %>%
print() %>%
ggplot(aes(author, percent, fill= author)) +
geom_bar(stat = "identity", alpha = .85, show.legend = FALSE) +
facet_wrap(~sentiment, scales = "free") +
coord_flip() +
labs(x = "sentiment",
y= "% of Sentiment Between Candidates")
speech_corpus_affin %>%
group_by(author, docnumber) %>%
mutate(numeric_sentiment = cumsum(score)) %>%
mutate(percent = as.integer(docnumber)) %>%
mutate(percent= cumsum(percent/sum(percent))) %>%
ggplot(aes(percent, numeric_sentiment, color = docnumber))+
geom_freqpoly(stat = "identity") +
facet_wrap(~author) %>%
geom_line(aes(y = 75), size =2.25, linetype = 2)
#Important for producing a readable table with the results for the final project
#This provide tangible
speech_corpus_affin %>%
group_by(author, docnumber) %>%
summarize(sum(score))
speech_corpus_affin %>%
group_by(author, docnumber, month, year) %>%
summarize(sum(score)) %>%
group_by(author, month, year) %>%
mutate(sum_sent = )