Skip to content

Instantly share code, notes, and snippets.

@lgelape

lgelape/abrilpelavida.R Secret

Created Apr 6, 2021
Embed
What would you like to do?
Código de análise da matéria sobre campanha #AbrilPelaVida, Núcleo Jornalismo
###################################################################################################
# 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