-
Notifications
You must be signed in to change notification settings - Fork 1
/
07_rtweet_E2.R
45 lines (31 loc) · 1.6 KB
/
07_rtweet_E2.R
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
writeLines("It is part of my CNPq-funded project and seeks to make corpus tools and R accessible. If you have any doubts or wish to make any research contact please send me an email. Rodrigo de Lima-Lopes [email protected]")
# Packages ----------------------------------------------------------------
library(dplyr)
library(tidytext)
library(ggplot2)
# Preparing the data ----------------------------------------------------------------
LI <- subset(presidents, screen_name == "LulaOficial")
JB <- subset(presidents, screen_name == "jairbolsonaro")
CG <- subset(presidents, screen_name == "cirogomes")
my.stopwords <- data.frame(word = quanteda::stopwords("pt"))
# **Lula** ----------------------------------------------------------------
LI.w <- LI %>%
unnest_tokens(word, text) %>% # separates each word
count(word, sort = TRUE) %>% # counts each word
anti_join(my.stopwords, by= "word") %>% # delete stopwords
mutate(freq = n / sum(n)) %>% # proportion (base 1)
mutate_at(vars(-matches("word|n")),~ .x * 100) # translates proportion to base 100
# **Jair Bolsonaro**----------------------------------------------------------------
JB.w <- JB %>%
unnest_tokens(word, text) %>%
count(word, sort = TRUE) %>%
anti_join(my.stopwords, by= "word") %>%
mutate(freq = n / sum(n)) %>%
mutate_at(vars(-matches("word|n")),~ .x * 100)
# **Ciro Gomes** ----------------------------------------------------------------
CG.w <- CG %>%
unnest_tokens(word, text) %>%
count(word, sort = TRUE) %>%
anti_join(my.stopwords, by= "word") %>%
mutate(freq = n / sum(n)) %>%
mutate_at(vars(-matches("word|n")),~ .x * 100)