-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDescriptive_Analysis_Of_2020_Twitter_Info_Ops.R
397 lines (284 loc) · 11.5 KB
/
Descriptive_Analysis_Of_2020_Twitter_Info_Ops.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
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
###### Package load ########
# Loads packages using the groundhog package. Groundhog enables reproducible
# analysis by recording the date the packages were used. It then downloads those
# exact package version upon later analysis, ensuring scripts run as intended.
library("groundhog")
pkgs <- c("tidyverse", "kableExtra", "lubridate", "gridExtra")
groundhog.library(pkgs, "2022-07-25")
# Disabling scientific notation to improve readability of certain variables.
# options(scipen=0, digits=7) # To return to default setting
options(scipen = 999)
# Setting seed for results replication
set.seed(12345)
###### Data Load ##########
# Load the three datasets of removed tweets acquired from Twitter and one baseline dataset. Feb 2021 removal
# of Russian IRA accounts, Feb 2021 removal of Iranian accounts, and Dec 2021
# removal of PRC Xinjiang-focused accounts.
russia_clean <- read_csv("russia_2021_cleaned.csv")
iran_clean <- read_csv("iran_2021_cleaned.csv")
china_clean <- read_csv("china_2021_cleaned.csv")
# Datasets comes from Arunava Kumar Chakraborty on Kaggle: https://www.kaggle.com/datasets/arunavakrchakraborty/covid19-twitter-dataset
# These datasets contains tweets about COVID-19 from August to September 2020 and April to June 2020, respectively
covid_2020_1 <- read_csv("Covid-19 Twitter Dataset (Apr-Jun 2020).csv")
covid_2020_2 <- read_csv("Covid-19 Twitter Dataset (Aug-Sep 2020).csv")
###### Descriptive Analysis ######
#### Russia ####
# How many unique accounts?
r1 <- length(unique(russia_clean[["userid"]]))
# How many unique tweets?
r2 <- length(unique(russia_clean[["tweetid"]]))
# Average tweets per account
r3 <- signif(r2 / r1, 4)
# Date of tweets
russia_clean$tweet_year <- year(russia_clean$tweet_time)
summary(russia_clean$tweet_year)
ggplot(russia_clean, aes(x = tweet_year)) +
geom_bar(fill = "#0072CE") +
scale_x_continuous(n.breaks = 11) +
xlab("Year")
# Account creation date
account_year_ru <- russia_clean %>%
select(userid, account_creation_date) %>%
unique()
account_year_ru$account_creation_date <- year(account_year_ru$account_creation_date)
summary(account_year_ru$account_creation_date)
ggplot(account_year_ru, aes(x = account_creation_date)) +
geom_bar(fill = "#0072CE", width = 0.7) +
scale_x_continuous(n.breaks = 11) +
xlab("Year")
# Follower count distribution - how many followers does each account have?
follower_ru <- russia_clean %>%
select(user_screen_name, follower_count) %>%
unique()
summary(follower_ru)
ggplot(follower_ru, aes(x = follower_count)) +
geom_histogram(fill = "#0072CE") +
xlab("Follower Count")
top_n(follower_ru, 10, follower_count) %>% # Top ten
arrange(desc(follower_count)) %>%
select(user_screen_name, follower_count)
# Following count distribution - how many other accounts does each account follow?
following_ru <- russia_clean %>%
select(userid, following_count) %>%
unique()
summary(following_ru)
ggplot(following_ru, aes(x = userid, y = following_count)) +
geom_col(fill = "#0072CE") +
scale_x_discrete("Accounts", labels = seq(1:r1)) +
scale_y_continuous(n.breaks = 10) +
ylab("Following Count")
top_n(following_ru, 10, following_count) %>% # Top ten
arrange(desc(following_count)) %>%
select(user_screen_name, following_count)
# Proportion of retweets
russia_clean %>%
summarize("Retweet" = mean(is_retweet) * 100,
"Not Retweet" = mean(!is_retweet) * 100)
# Amplification metrics - Mean and median of quotes, replies, retweets, and likes for tweets in the dataset
# Quotes
summary(russia_clean$quote_count)
ggplot(russia_clean, aes(x = quote_count)) +
geom_area(stat = "bin", fill = "#0072CE") +
ylab("Number of Quote Tweets")
top_n(russia_clean, 10, quote_count) %>% # Top ten
arrange(desc(quote_count)) %>%
select(user_screen_name, quote_count)
# Replies
summary(russia_clean$reply_count)
ggplot(russia_clean, aes(x = reply_count)) +
geom_histogram(fill = "#0072CE") +
ylab("Number of Replies")
top_n(russia_clean, 10, reply_count) %>% # Top ten
arrange(desc(reply_count)) %>%
select(user_screen_name, reply_count)
# Retweets
summary(russia_clean$retweet_count)
ggplot(russia_clean, aes(y = retweet_count)) +
geom_boxplot(fill = "#0072CE") +
ylab("Number of Retweets")
top_n(russia_clean, 10, retweet_count) %>% # Top ten
arrange(desc(retweet_count)) %>%
select(user_screen_name, retweet_count)
# Likes
summary(russia_clean$like_count)
ggplot(russia_clean, aes(y = like_count)) +
geom_boxplot(fill = "#0072CE") +
ylab("Number of Likes")
top_n(russia_clean, 10, like_count) %>% # Top ten
arrange(desc(like_count)) %>%
select(user_screen_name, like_count)
# Would be great to have - impressions: how many people were these tweets served to?
#### Iran ####
# How many unique accounts?
i1 <- length(unique(iran_clean[["userid"]]))
# How many unique tweets?
i2 <- length(unique(iran_clean[["tweetid"]]))
# Average tweets per account
i3 <- signif(i2 / i1, 4)
# Date and time of tweets
iran_clean$tweet_year <- year(iran_clean$tweet_time)
summary(iran_clean$tweet_year)
ggplot(iran_clean, aes(x = tweet_year)) +
geom_bar(fill = "#009639")+
scale_x_continuous(n.breaks = 11) +
xlab("Year")
# Account creation date
account_year_ir <- iran_clean %>%
select(userid, account_creation_date) %>%
unique()
account_year_ir$account_creation_date <- year(account_year_ir$account_creation_date)
summary(account_year_ir$account_creation_date)
ggplot(account_year_ir, aes(x = account_creation_date)) +
geom_bar(fill = "#009639", width = 0.7) +
scale_x_continuous(n.breaks = 11) +
xlab("Year")
# Follower count distribution - how many followers does each account have?
follower_ir <- iran_clean %>%
select(user_screen_name, follower_count) %>%
unique()
summary(follower_ir)
ggplot(follower_ir, aes(x = follower_count)) +
stat_density(fill = "#009639") +
scale_x_continuous("Number of Followers") +
scale_y_continuous(n.breaks = 12)
top_n(follower_ir, 10, follower_count) %>% # Top ten
arrange(desc(follower_count)) %>%
select(user_screen_name, follower_count)
# Following count distribution - how many other accounts does each account follow?
following_ir <- iran_clean %>%
select(userid, following_count) %>%
unique()
summary(following_ir)
ggplot(following_ir, aes(x = following_count)) +
stat_density(fill = "#009639") +
scale_x_continuous("Accounts Followed") +
scale_y_continuous(n.breaks = 10)
top_n(following_ir, 10, following_count) %>% # Top ten
arrange(desc(following_count)) %>%
select(user_screen_name, following_count)
# Proportion of retweets
iran_clean %>%
summarize("Retweet" = mean(is_retweet) * 100,
"Not Retweet" = mean(!is_retweet) * 100)
# Amplification metrics - Mean and median of quotes, replies, retweets, and likes for tweets in the dataset
# Quotes
summary(iran_clean$quote_count)
ggplot(iran_clean, aes(y = quote_count)) +
geom_boxplot(fill = "#009639") +
ylab("Number of Quote Tweets")
top_n(iran_clean, 10, quote_count) %>% # Top ten
arrange(desc(quote_count)) %>%
select(user_screen_name, quote_count)
# Replies
summary(iran_clean$reply_count)
ggplot(iran_clean, aes(y = reply_count)) +
geom_boxplot(fill = "#009639") +
ylab("Number of Replies")
top_n(iran_clean, 10, reply_count) %>% # Top ten
arrange(desc(reply_count)) %>%
select(user_screen_name, reply_count)
# Retweets
summary(iran_clean$retweet_count)
ggplot(iran_clean, aes(y = retweet_count)) +
geom_boxplot(fill = "#009639") +
ylab("Number of Retweets")
top_n(iran_clean, 10, retweet_count) %>% # Top ten
arrange(desc(retweet_count)) %>%
select(user_screen_name, retweet_count)
# Likes
summary(iran_clean$like_count)
ggplot(iran_clean, aes(y = like_count)) +
geom_boxplot(fill = "#009639") +
ylab("Number of Likes")
top_n(iran_clean, 10, like_count) %>% # Top ten
arrange(desc(like_count)) %>%
select(user_screen_name, like_count)
# Would be great to have - impressions: how many people were these tweets served to?
#### China ####
# How many unique accounts?
c1 <- length(unique(china_clean[["userid"]]))
# How many unique tweets?
c2 <- length(unique(china_clean[["tweetid"]]))
# Average tweets per account
c3 <- signif(c2 / c1, 4)
# Date of tweets
china_clean$tweet_month <- month(china_clean$tweet_time)
# Dataset contains 4 months of tweets, so time scale was changed to represent this
tt3 <- ggplot(china_clean, aes(x = tweet_month)) +
geom_bar(fill = "#C8102E") +
scale_x_binned(labels = cmonths) +
xlab("Months in 2021")
tt3
# Account creation date
account_year_ch <- china_clean %>%
select(userid, account_creation_date) %>%
unique()
account_year_ch$account_creation_date <- year(account_year_ch$account_creation_date)
summary(account_year_ch$account_creation_date)
table(account_year_ch$account_creation_date)
ggplot(account_year_ch, aes(x = account_creation_date)) +
geom_bar(fill = "#C8102E") +
xlab("Year")
# Follower count distribution - how many followers does each account have?
follower_ch <- china_clean %>%
select(userid, follower_count) %>%
unique()
summary(follower_ch)
ggplot(follower_ch, aes(x = follower_count)) +
stat_density(fill = "#C8102E") +
scale_x_continuous("Number of Followers") +
scale_y_continuous(n.breaks = 12)
top_n(follower_ch, 10, follower_count) %>% # Top ten
arrange(desc(follower_count)) %>%
select(user_screen_name, follower_count)
# Following count distribution - how many other accounts does each account follow?
following_ch <- china_clean %>%
select(userid, following_count) %>%
unique()
summary(following_ch)
ggplot(following_ch, aes(x = following_count)) +
stat_density(fill = "#C8102E") +
scale_x_continuous("Accounts Followed") +
scale_y_continuous(n.breaks = 10)
top_n(following_ch, 10, following_count) %>% # Top ten
arrange(desc(following_count)) %>%
select(user_screen_name, following_count)
# Proportion of retweets
china_clean %>%
summarize("Retweet" = mean(is_retweet) * 100,
"Not Retweet" = mean(!is_retweet) * 100)
# Amplification metrics - Mean and median of quotes, replies, retweets, and likes for tweets in the dataset
# Quotes
summary(china_clean$quote_count)
ggplot(china_clean, aes(y = quote_count)) +
geom_boxplot(fill = "#C8102E") +
ylab("Number of Quote Tweets")
top_n(china_clean, 10, quote_count) %>% # Top ten
arrange(desc(quote_count)) %>%
select(user_screen_name, quote_count)
# Replies
summary(china_clean$reply_count)
ggplot(china_clean, aes(y = reply_count)) +
geom_boxplot(fill = "#C8102E") +
ylab("Number of Replies")
top_n(china_clean, 10, reply_count) %>% # Top ten
arrange(desc(reply_count)) %>%
select(user_screen_name, reply_count)
# Retweets
summary(china_clean$retweet_count)
ggplot(china_clean, aes(y = retweet_count)) +
geom_boxplot(fill = "#C8102E") +
ylab("Number of Retweets")
top_n(china_clean, 10, retweet_count) %>% # Top ten
arrange(desc(retweet_count)) %>%
select(user_screen_name, retweet_count)
# Likes
summary(china_clean$like_count)
ggplot(china_clean, aes(y = like_count)) +
geom_boxplot(fill = "#C8102E") +
ylab("Number of Likes")
top_n(china_clean, 10, like_count) %>% # Top ten
arrange(desc(like_count)) %>%
select(user_screen_name, like_count)
##### Presenting data #####
#grid.arrange(plot1, plot2, plot3, ncol=3)