-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
512 lines (512 loc) · 29.3 KB
/
.Rhistory
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
}
control_list_ngram = list(tokenize = NLP_tokenizer)
#### Build a term-document matrix ####
dtm <- TermDocumentMatrix(docs,control_list_ngram)
dtm_f <- TermDocumentMatrix(docs_f,control_list_ngram)
m <- as.matrix(dtm_f)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v) %>% filter(!grepl("na",word))
head(d, 40)
#### Generate the Word Cloud ####
set.seed(1234)
wordcloud(words = d$word, freq = d$freq, min.freq = 1,
max.words=30, random.order=FALSE, rot.per=0,
colors=brewer.pal(8, "Dark2"))
View(d)
#### Tokenizer / N-Grammer ####
token_size <- 2
NLP_tokenizer <- function(x) {
unlist(lapply(ngrams(words(x), token_size), paste, collapse = " "), use.names = FALSE)
}
control_list_ngram = list(tokenize = NLP_tokenizer)
#### Build a term-document matrix ####
dtm <- TermDocumentMatrix(docs,control_list_ngram)
dtm_f <- TermDocumentMatrix(docs_f,control_list_ngram)
m <- as.matrix(dtm_f)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v) %>% filter(!grepl("na",word))
head(d, 40)
#### Generate the Word Cloud ####
set.seed(1234)
wordcloud(words = d$word, freq = d$freq, min.freq = 1,
max.words=30, random.order=FALSE, rot.per=0,
colors=brewer.pal(8, "Dark2"))
wordcloud(words = d$word, freq = d$freq, min.freq = 1,
max.words=30, random.order=FALSE, rot.per=0,
colors=brewer.pal(8, "Dark2"))
#### Tokenizer / N-Grammer ####
token_size <- 2
NLP_tokenizer <- function(x) {
unlist(lapply(ngrams(words(x), token_size), paste, collapse = " "), use.names = FALSE)
}
control_list_ngram = list(tokenize = NLP_tokenizer)
#### Build a term-document matrix ####
dtm <- TermDocumentMatrix(docs,control_list_ngram)
dtm_f <- TermDocumentMatrix(docs_f,control_list_ngram)
m <- as.matrix(dtm_f)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v) %>% filter(!grepl("na",word))
head(d, 40)
#### Generate the Word Cloud ####
set.seed(1234)
wordcloud(words = d$word, freq = d$freq, min.freq = 1,
max.words=30, random.order=FALSE, rot.per=0,
colors=brewer.pal(8, "Dark2"))
#### Create a graph for bigrams ####
att_sep <- ifelse(token_size==2,list(c("word1","word2")),list(c("word1", "word2","word3"))) %>% .[[1]]
dd <- d %>% filter(!grepl("na",word)) %>% separate(word, att_sep, sep = "_")
dd %>% filter(freq>100) %>% visualize_bigrams()
dd
#### Create a graph for bigrams ####
att_sep <- ifelse(token_size==2,list(c("word1","word2")),list(c("word1", "word2","word3"))) %>% .[[1]]
View(att_sep)
dd <- d %>% filter(!grepl("na",word)) %>% separate(word, att_sep, sep = "_")
View(dd)
#### Create a graph for bigrams ####
att_sep <- ifelse(token_size==2,list(c("word1","word2")),list(c("word1", "word2","word3"))) %>% .[[1]]
dd <- d %>% filter(!grepl("na",word)) %>% separate(word, att_sep, sep = " ")
dd %>% filter(freq>100) %>% visualize_bigrams()
View(dd)
dd %>% filter(freq>100) %>% visualize_bigrams()
dd %>% filter(freq>100)
dd %>% filter(freq>10) %>% visualize_bigrams()
dd %>% filter(freq>2) %>% visualize_bigrams()
dd %>% filter(freq>5) %>% visualize_bigrams()
dd %>% filter(freq>10) %>% visualize_bigrams()
findFreqTerms(dtm, lowfreq = 1000)
ass <- findAssocs(dtm, terms = "ipad", corlimit = 0.15)
ass
findFreqTerms(dtm, lowfreq = 100)
findFreqTerms(dtm, lowfreq = 10)
ass <- findAssocs(dtm, terms = "ipad", corlimit = 0.15)
ass
ass <- findAssocs(dtm, terms = "ipad", corlimit = 0.1)
ass <- findAssocs(dtm, terms = "ipad", corlimit = 0.01)
ass
View(dtm)
d$word <- factor(d$word,rev(unique(d$word))) # to make sure "Words" are plotted in correct order rather than alphabetically
ggplot(data=d[c(1:3,5:15),],mapping=aes(x=word,y=freq)) + geom_col(fill="deepskyblue") +
labs(y="Word frequencies",x="Words",title="Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1)) +
coord_flip()
barplot(d[1:20,]$freq, las = 2, names.arg = d[1:20,]$word,
col ="lightblue", main ="Most frequent words",
ylab = "Word frequencies") + coord_flip()
ggplot(data=d[c(1:3,5:15),],mapping=aes(x=word,y=freq)) + geom_col(fill="deepskyblue") +
labs(y="Word frequencies",x="Words",title="Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1)) +
coord_flip()
ggplot(data=d[,],mapping=aes(x=word,y=freq)) + geom_col(fill="deepskyblue") +
labs(y="Word frequencies",x="Words",title="Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1)) +
coord_flip()
ggplot(data=d[1:20,],mapping=aes(x=word,y=freq)) + geom_col(fill="deepskyblue") +
labs(y="Word frequencies",x="Words",title="Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1)) +
coord_flip()
ggplot(data=d[1:20,],mapping=aes(x=word,y=freq)) + geom_col(fill="deepskyblue") +
labs(y="Word frequencies",x="Words",title="Most frequent pairs of words") + theme(axis.text.x=element_text(angle=60,hjust=1)) +
coord_flip()
here
here()
ggsave("./output/Q17_wordpairfreq.png",width = 40, height = 20, dpi=300,units ="cm")
ggplot(data=d[1:20,],mapping=aes(x=word,y=freq)) + geom_col(fill="deepskyblue") +
labs(y="Word frequencies",x="Words",title="Most frequent pairs of words") + theme(axis.text.x=element_text(angle=60,hjust=1)) +
coord_flip()+ labs(caption="Frequency that two words appear next to each other in a reply (excluding connectors, ponctuation etc)")
ggplot(data=d[1:20,],mapping=aes(x=word,y=freq)) + geom_col(fill="deepskyblue") +
labs(y="Word frequencies",x="Words",title="Q17 - Most frequent pairs of words") + theme(axis.text.x=element_text(angle=60,hjust=1)) +
coord_flip()+ labs(caption="Frequency that two words appear next to each other in a reply (excluding connectors, ponctuation etc)")
ggplot(data=d[1:20,],mapping=aes(x=word,y=freq)) + geom_col(fill="deepskyblue") +
labs(y="Word frequencies",x="Words",title="Q17 - Most frequent pairs of words") + theme(axis.text.x=element_text(angle=60,hjust=1)) +
coord_flip()+ labs(caption="Frequency that two words appear next to each other in a reply (excluding connectors, common stopwords, punctuation etc)")
ggsave("./output/Q17_wordpairfreq.png",width = 40, height = 20, dpi=300,units ="cm")
#### Generate the Word Cloud ####
set.seed(1234)
wordcloud(words = d$word, freq = d$freq, min.freq = 1,
max.words=30, random.order=FALSE, rot.per=0,
colors=brewer.pal(8, "Dark2"))
ggsave("./output/Q17_wordpaircloud.png",width = 40, height = 20, dpi=300,units ="cm")
wordcloud(words = d$word, freq = d$freq, min.freq = 1,
max.words=30, random.order=FALSE, rot.per=0,
colors=brewer.pal(8, "Dark2"))
ggsave("./output/Q17_wordpaircloud.png",width = 40, height = 20, dpi=300,units ="cm")
?wordcloud
install.packages("webshot")
install.packages("htmlwidgets")
library(webshot) # to save wordclouds as png
library(htmlwidgets) # to help save wordclouds as png
webshot::install_phantomjs()
webshot::install_phantomjs(force=TRUE)
saveWidget(my_graph,"tmp.html",selfcontained = F)
my_cloud<-wordcloud(words = d$word, freq = d$freq, min.freq = 1,
max.words=30, random.order=FALSE, rot.per=0,
colors=brewer.pal(8, "Dark2"))
saveWidget(my_cloud,"tmp.html",selfcontained = F)
library(webshot) # to save wordclouds as png
library(htmlwidgets) # to help save wordclouds as png
saveWidget(my_cloud,"tmp.html",selfcontained = F)
my_cloud<-wordcloud(words = d$word, freq = d$freq, min.freq = 1,
max.words=30, random.order=FALSE, rot.per=0,
colors=brewer.pal(8, "Dark2"))
my_cloud<-wordcloud2(words = d$word, freq = d$freq, min.freq = 1,
max.words=30, random.order=FALSE, rot.per=0,
colors=brewer.pal(8, "Dark2"))
#### Sentiment analysis (mainly for L) ####
# for words, not grams!
dtm_w <- TermDocumentMatrix(docs)
m_w <- as.matrix(dtm_w)
v_w <- sort(rowSums(m_w),decreasing=TRUE)
d_w <- data.frame(word = names(v_w),freq=v_w)
head(d_w, 40)
head(d,40)
ggplot(data=d[1:20,],mapping=aes(x=word,y=freq)) + geom_col(fill="deepskyblue") +
labs(y="Word frequencies",x="Words",title="Q17 - Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1)) +
coord_flip()+ labs(caption="Frequency that a word appears (top is excluding connectors, common stopwords, punctuation etc)")
ggplot(data=d_w[1:20,],mapping=aes(x=word,y=freq)) + geom_col(fill="deepskyblue") +
labs(y="Word frequencies",x="Words",title="Q17 - Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1)) +
coord_flip()+ labs(caption="Frequency that a word appears (top is excluding connectors, common stopwords, punctuation etc)")
ggplot(data=v_w[1:20,],mapping=aes(x=word,y=freq)) + geom_col(fill="deepskyblue") +
labs(y="Word frequencies",x="Words",title="Q17 - Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1)) +
coord_flip()+ labs(caption="Frequency that a word appears (top is excluding connectors, common stopwords, punctuation etc)")
head(v_w)
d_w <- data.frame(word = names(v_w),freq=v_w)
ggplot(data=d_w[1:20,],mapping=aes(x=word,y=freq)) + geom_col(fill="deepskyblue") +
labs(y="Word frequencies",x="Words",title="Q17 - Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1)) +
coord_flip()+ labs(caption="Frequency that a word appears (top is excluding connectors, common stopwords, punctuation etc)")
head(d_w)
View(d_w)
d_W $word <- factor(d_w$word,rev(unique(d_w$word)))
d_w$word <- factor(d_w$word,rev(unique(d_w$word)))
ggplot(data=d_w[1:20,],mapping=aes(x=word,y=freq)) + geom_col(fill="deepskyblue") +
labs(y="Word frequencies",x="Words",title="Q17 - Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1)) +
coord_flip()+ labs(caption="Frequency that a word appears (top is excluding connectors, common stopwords, punctuation etc)")
ggsave("./output/Q17_wordsinglefreq.png",width = 40, height = 20, dpi=300,units ="cm")
sentiments_afinn <- get_sentiments("afinn")
d_w_sen <- inner_join(d_w,
sentiments_afinn,
by=c("word")) #%>%
(d_w_sen %>% count(value)) # amount of distinct words per score
(d_w_sen %>% group_by(value) %>% summarise(freq_all = sum(freq))) # overall frequency of use of words per score
d_w_bing <- inner_join(d_w,get_sentiments("bing"),by="word") %>%
acast(word ~ sentiment, value.var="freq",fill=0)
d_w_bing %>% comparison.cloud(colors=c("red","deepskyblue"),max.words=10)
View(d_w_bing)
d_w_bing_nocast <- inner_join(d_w,get_sentiments("bing"),by="word")
View(d_w_bing_nocast)
myceil <- d_w_bing_nocast$freq %>% max()
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"], scale = c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"])/myceil, 0.5))
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"], scale = c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"])/myceil, 0.5))
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"], scale = c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"])/myceil, 0.5))
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"], scale = c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"])/myceil, 0.5),colors="blue")
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"], scale = c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"])/myceil, 0.5),colors="red")
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"], scale = c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"])/myceil, 5),colors="blue")
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"], scale = c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"])/myceil, 1),colors="blue")
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"], scale = c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"])/myceil, 1),colors="red")
View(d_w)
ggplot(data=d_w_bing_nocast[1:20,],mapping=aes(x=word,y=freq)) + geom_col(aes(fill=sentiment)) +
labs(y="Word frequencies",x="Words",title="Q17 - Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1)) +
ggplot(data=d_w_bing_nocast[1:20,],mapping=aes(x=word,y=freq)) + geom_col(aes(fill=sentiment)) +
labs(y="Word frequencies",x="Words",title="Q17 - Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1))
ggplot(data=d_w_bing_nocast[1:20,],mapping=aes(x=word,y=freq)) + geom_col(aes(color=sentiment)) +
labs(y="Word frequencies",x="Words",title="Q17 - Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1))
ggplot(data=d_w_bing_nocast[1:20,],mapping=aes(x=word,y=freq)) + geom_col(aes(color=sentiment)) +
facet_wrap(~sentiment)+
labs(y="Word frequencies",x="Words",title="Q17 - Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1))
ggplot(data=d_w_bing_nocast[1:20,],mapping=aes(x=word,y=freq)) + geom_col(aes(fill=sentiment)) +
facet_wrap(~sentiment)+
labs(y="Word frequencies",x="Words",title="Q17 - Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1))
ggplot(data=d_w_bing_nocast[1:20,],mapping=aes(x=word,y=freq)) + geom_col(aes(fill=sentiment)) +
#facet_wrap(~sentiment)+
labs(y="Word frequencies",x="Words",title="Q17 - Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1))
ggplot(data=d_w_bing_nocast[1:40,],mapping=aes(x=word,y=freq)) + geom_col(aes(fill=sentiment)) +
#facet_wrap(~sentiment)+
labs(y="Word frequencies",x="Words",title="Q17 - Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1))
ggplot(data=d_w_bing_nocast[1:40,],mapping=aes(x=word,y=freq)) + geom_col(aes(fill=sentiment)) +
facet_wrap(~sentiment,drop=TRUE)+
labs(y="Word frequencies",x="Words",title="Q17 - Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1))
ggplot(data=d_w_bing_nocast[1:40,],mapping=aes(x=word,y=freq)) + geom_col(aes(fill=sentiment)) +
facet_wrap(~sentiment,scales="free_x")+
labs(y="Word frequencies",x="Words",title="Q17 - Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1))
d_w_bing_nocast <- inner_join(d_w,get_sentiments("bing"),by="word") %>% arrange(desh(freq))
d_w_bing_nocast <- inner_join(d_w,get_sentiments("bing"),by="word") %>% arrange(desc(freq))
d_w_bing_nocast$word <- factor(d_w_bing_nocast$word,rev(unique(d_w_bing_nocast$word)))
myceil <- d_w_bing_nocast$freq %>% max()
d_w_bing <- inner_join(d_w,get_sentiments("bing"),by="word") %>%
acast(word ~ sentiment, value.var="freq",fill=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"], scale = c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"])/myceil, 1),colors="blue")
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"], scale = c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"])/myceil, 1),colors="red")
d_w_bing %>% comparison.cloud(colors=c("red","deepskyblue"),max.words=10) #nb: scale is relative to each cat, so can't compare size of 'positive' and negative'
ggplot(data=d_w_bing_nocast[1:40,],mapping=aes(x=word,y=freq)) + geom_col(aes(fill=sentiment)) +
facet_wrap(~sentiment,scales="free_x")+
labs(y="Word frequencies",x="Words",title="Q17 - Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1))
ggplot(data=d_w_bing_nocast[1:40,],mapping=aes(x=word,y=freq)) + geom_col(aes(fill=sentiment)) +
#facet_wrap(~sentiment,scales="free_x")+
labs(y="Word frequencies",x="Words",title="Q17 - Most frequent words") + theme(axis.text.x=element_text(angle=60,hjust=1))
ggplot(data=d_w_bing_nocast[1:40,],mapping=aes(x=word,y=freq)) + geom_col(aes(fill=sentiment)) +
#facet_wrap(~sentiment,scales="free_x")+
labs(y="Word frequencies",x="Words",title="40 most frequent words with a positive or negative association") +
theme(axis.text.x=element_text(angle=60,hjust=1))+
labs(caption="Sentiment analysis informed by the Bing lexicon of positive and negative connotation words.\n Note: words not present in the lexicon ommitted.")
ggplot(data=d_w_bing_nocast[1:40,],mapping=aes(x=word,y=freq)) + geom_col(aes(fill=sentiment)) +
#facet_wrap(~sentiment,scales="free_x")+
labs(y="Q17. Word frequencies",x="Words",title="40 most frequent words with a positive or negative association") +
theme(axis.text.x=element_text(angle=60,hjust=1))+
labs(caption="Sentiment analysis informed by the Bing lexicon of positive and negative connotation words.\n Note: words not present in the lexicon ommitted.")
ggsave("./output/Q17_sentimentfreq.png",width = 40, height = 20, dpi=300,units ="cm")
ggplot(data=d_w_bing_nocast[1:40,],mapping=aes(x=word,y=freq)) + geom_col(aes(fill=sentiment)) +
#facet_wrap(~sentiment,scales="free_x")+
labs(y="Q17 word frequencies",x="Words",title="Q17. 40 most frequent words with a positive or negative association") +
theme(axis.text.x=element_text(angle=60,hjust=1))+
labs(caption="Sentiment analysis informed by the Bing lexicon of positive and negative connotation words.\n Note: words not present in the lexicon ommitted.")
ggsave("./output/Q17_sentimentfreq.png",width = 40, height = 20, dpi=300,units ="cm")
(d_w_sen %>% group_by(value) %>% summarise(freq_all = sum(freq))) # overall frequency of use of words per score
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"], scale = c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"])/myceil, 1),colors="blue")
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"], scale = c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"])/myceil, 1),colors="red")
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"], scale = c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"])/myceil, 1),colors="blue",rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"], scale = c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"])/myceil, 1),colors="red",rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"], scale = c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"])/myceil, 1),colors="blue",rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"], scale = c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"])/myceil, 1),colors="red",rot.per=0)
myceil
d_w_bing_nocast <- inner_join(d_w,get_sentiments("bing"),by="word") %>% arrange(desc(freq))
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"], scale = c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"])/myceil, 1),colors="blue",rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"], scale = c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"])/myceil, 1),colors="red",rot.per=0)
View(c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"])/myceil, 1))
View(c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"])/myceil, 1))
View(c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"])/myceil, 0.5))
View(c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"])/myceil, 0.5))
View(c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"])/myceil, 1))
View(c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"])/myceil, 0.5))
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"], scale = c(8*max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"])/myceil, 0.5),colors="blue",rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"], scale = myrange,colors="blue",rot.per=0)
myrange=c(0.5,8)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"], scale = myrange,colors="blue",rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"], scale = myrange,colors="red",rot.per=0)
?wordcloud
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"], scale = myrange,colors="blue",rot.per=0)
myrange=c(8,0.5)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"], d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"], scale = myrange,colors="blue",rot.per=0)
myceil <- d_w_bing_nocast$freq %>% filter(freq>5) %>% max()
myceil <- d_w_bing_nocast$freq %>% max()
myceil <- d_w_bing_nocast$freq %>% max()
myfloor <- 5
myrange
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"],
min.freq=myfloor,
scale = myrange,
colors="blue",
rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"],
min.freq=myfloor,
scale = myrange,
colors="red",
rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"],
min.freq=myfloor,
scale = myrange,
colors="blue",
rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"],
min.freq=myfloor,
scale = c(0,max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"]) /myceil),
colors="red",
rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"],
min.freq=myfloor,
scale = c(0.5,max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"]) /myceil),
colors="red",
rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"],
min.freq=myfloor,
scale = myrange,
colors="blue",
rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"],
min.freq=myfloor,
scale = myrange,
colors="blue",
rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"],
min.freq=myfloor,
scale = c(0.5,8),
colors="blue",
rot.per=0)
myrange
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"],
min.freq=myfloor,
scale = myrange,
colors="blue",
rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"],
min.freq=myfloor,
scale = c(max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"]) /myceil,0.5),
colors="red",
rot.per=0)
max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"])
max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"]) /myceil
mymin <- 5
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"],
min.freq=myfloor,
scale = c(max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"]) /myceil,0)+myfloor,
colors="red",
rot.per=0)
myfloor <- 0.5
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"],
min.freq=myfloor,
scale = c(max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"]) /myceil,0)+myfloor,
colors="red",
rot.per=0)
myfloor <- 5
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"],
min.freq=myfloor,
scale = myrange,
colors="blue",
rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"],
min.freq=myfloor,
scale = c(max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"]) /myceil,0)+myrange(2),
colors="red",
rot.per=0)
myrange=c(8,0.5)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"],
min.freq=myfloor,
scale = c(max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"]) /myceil,0)+myrange(2),
colors="red",
rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"],
min.freq=myfloor,
scale = c(max(d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"]) /myceil,0)+myrange[2],
colors="red",
rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"],
min.freq=myfloor,
scale = myrange,
colors="blue",
rot.per=0)
myrange=c(8,0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"],
min.freq=myfloor,
scale = myrange,
colors="blue",
rot.per=0)
myrange=c(8,0.5)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"],
min.freq=myfloor,
scale = myrange,
colors="blue",
rot.per=0)
myceil <- d_w_bing_nocast$freq %>% max()
myfloor <- 5
aux <- d_w_bing_nocast %>% filter(freq>=myfloor)
aux$Scale <- rescale(aux$freq,to=myrange)
install.packages("scales")
#library(webshot) # to save wordclouds as png
#library(htmlwidgets) # to help save wordclouds as png
library(scales)
aux$Scale <- rescale(aux$freq,to=myrange)
View(aux)
sapply(aux,min)
sapply(aux,min,2)
sapply(aux,min,1)
lapply(aux,c(min,max))
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"],
min.freq=myfloor,
scale = c(max(d_w_bing_nocast$Scale[d_w_bing_nocast$sentiment == "negative"]),min(d_w_bing_nocast$Scale[d_w_bing_nocast$sentiment == "negative"])),
colors="red",
rot.per=0)
library(tidyverse)
library(modelr)
library(readxl)
library(sandwich)
library(lmtest)
library(utils)
library(openxlsx)
library("tm")
library("SnowballC")
library("wordcloud")
library("RColorBrewer")
library(qdap)
library(rJava)
#library(RWeka)
library(janeaustenr)
library(tidytext) # for sentiments
library(textdata) # for AFINN
library(igraph) # masks decompose, spectrum (from stats), union (from base)
library(ggraph) #
library(reshape2) # to be able to use 'acast' function
#library(webshot) # to save wordclouds as png
#library(htmlwidgets) # to help save wordclouds as png
library(scales)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"],
min.freq=myfloor,
scale = myrange,
colors="blue",
rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"],
min.freq=myfloor,
scale = c(max(d_w_bing_nocast$Scale[d_w_bing_nocast$sentiment == "negative"]),min(d_w_bing_nocast$Scale[d_w_bing_nocast$sentiment == "negative"])),
colors="red",
rot.per=0)
scale = c(max(d_w_bing_nocast$Scale[d_w_bing_nocast$sentiment == "negative"]),min(d_w_bing_nocast$Scale[d_w_bing_nocast$sentiment == "negative"]))
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"],
min.freq=myfloor,
scale = c(max(aux$Scale[aux$sentiment == "negative"]),min(aux$Scale[aux$sentiment == "negative"])),
colors="red",
rot.per=0)
scale = c(max(aux$Scale[aux$sentiment == "negative"]),min(aux$Scale[aux$sentiment == "negative"]))
scale
aux <- d_w_bing_nocast %>% filter(freq>=myfloor)
aux$Scale <- rescale(aux$freq,to=rev(myrange))
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"],
min.freq=myfloor,
scale = myrange,
colors="blue",
rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"],
min.freq=myfloor,
scale = c(max(aux$Scale[aux$sentiment == "negative"]),min(aux$Scale[aux$sentiment == "negative"])),
colors="red",
rot.per=0)
myceil <- d_w_bing_nocast$freq %>% max()
myrange=c(8,0.5)
myfloor <- 4
aux <- d_w_bing_nocast %>% filter(freq>=myfloor)
aux$Scale <- rescale(aux$freq,to=rev(myrange))
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "positive"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "positive"],
min.freq=myfloor,
scale = myrange,
colors="blue",
rot.per=0)
wordcloud(d_w_bing_nocast$word[d_w_bing_nocast$sentiment == "negative"],
d_w_bing_nocast$freq[d_w_bing_nocast$sentiment == "negative"],
min.freq=myfloor,
scale = c(max(aux$Scale[aux$sentiment == "negative"]),min(aux$Scale[aux$sentiment == "negative"])),
colors="red",
rot.per=0)
my_cloud<-wordcloud(words = d_w$word, freq = d_w$freq, min.freq = 1,
max.words=30, random.order=FALSE, rot.per=0,
colors=brewer.pal(8, "Dark2"))
my_cloud<-wordcloud(words = d_w$word, freq = d_w$freq, min.freq = 1,
max.words=40, random.order=FALSE, rot.per=0,
colors=brewer.pal(8, "Dark2"))