Created
April 6, 2021 00:13
-
-
Save lgelape/faa68417428bfcf01590473ab24f2d6b to your computer and use it in GitHub Desktop.
Código de análise da matéria sobre campanha #AbrilPelaVida, Núcleo Jornalismo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################################### | |
# Pacotes | |
library(dplyr) | |
library(rtweet) | |
library(ggplot2) | |
################################################################################################### | |
# Busca tweets que podem conter a expressao que estamos buscando | |
hashtag_busca1 <- search_tweets("AbrilPelaVida", n = 18000, | |
retryonratelimit = T, | |
include_rts = F) | |
hashtag_busca2 <- search_tweets("abrilpelavida", n = 18000, | |
retryonratelimit = T, | |
include_rts = F) | |
hashtag_busca3 <- search_tweets("\"abril pela vida\"", n = 18000, | |
retryonratelimit = T, | |
include_rts = F) | |
hashtag_busca4 <- search_tweets("#abrilpelavida", n = 18000, | |
retryonratelimit = T, | |
include_rts = F) | |
hashtag_busca5 <- search_tweets("#AbrilPelaVida", n = 18000, | |
retryonratelimit = T, | |
include_rts = F) | |
# Identifica o n. de tweets unicos | |
status_urls <- length(unique(c(hashtag_busca1$status_url, hashtag_busca2$status_url, | |
hashtag_busca3$status_url, hashtag_busca4$status_url, | |
hashtag_busca5$status_url))) | |
# Cria a base final, eliminando as duplicacoes e criando a variavel interacoes | |
banco_final <- bind_rows(hashtag_busca1, hashtag_busca2, hashtag_busca3, | |
hashtag_busca4, hashtag_busca5) %>% | |
select(user_id, status_id, screen_name, created_at, status_url, | |
retweet_count, favorite_count, is_quote, text) %>% | |
distinct() %>% | |
mutate(interacoes = retweet_count + favorite_count) %>% | |
group_by(status_id) %>% | |
slice_max(interacoes, n = 1) %>% | |
ungroup() | |
################################################################################################### | |
# Volume total de interacoes | |
sum(banco_final$interacoes) | |
# Numero total de usuarios que fizeram tweets unicos | |
length(unique(banco_final$user_id)) | |
# N. de tweets/dia | |
tweets_dia <- banco_final %>% | |
mutate(dia = as.Date(created_at)) %>% | |
group_by(dia) %>% | |
summarise(numero = n()) %>% | |
ungroup() | |
# Volume de interacoes/dia | |
interacoes_dia <- banco_final %>% | |
mutate(dia = as.Date(created_at)) %>% | |
group_by(dia) %>% | |
summarise(interacoes_dia = sum(interacoes)) %>% | |
ungroup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment