Created
April 9, 2020 01:24
-
-
Save lgelape/eab7800d7e38cf9f90d6a4a8f8fd0693 to your computer and use it in GitHub Desktop.
This file contains 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
library(dplyr) | |
library(rtweet) | |
library(ggplot2) | |
library(chron) | |
supermercado_busca <- search_tweets("\"estou no supermercado\"", n = 18000, | |
retryonratelimit = T, | |
include_rts = F) | |
supermercado <- supermercado_busca | |
supermercado <- supermercado %>% | |
filter(lang == "pt") | |
# regulariza o formato da data do tweet, corrige para fuso certo | |
supermercado$created_at <- as.POSIXct(strptime(supermercado$created_at, "%Y-%m-%d %H:%M:%S")) | |
supermercado$created_at <- supermercado$created_at - hours(3) | |
supermercado$dia <- as.POSIXct(strptime(supermercado$created_at, "%Y-%m-%d")) | |
# cria coluna com minuto arredondado | |
supermercado$min_redondo <- round(supermercado$created_at, units = "hours") | |
supermercado$horario_tweet <- times(strftime(supermercado$min_redondo,"%H:%M:%S")) | |
contagem <- supermercado %>% | |
group_by(horario_tweet) %>% | |
count() %>% | |
ungroup() %>% | |
mutate(percentual = round((n/sum(n))*100, digits = 1)) | |
contagem$horario_tweet <- factor(as.character(contagem$horario_tweet), | |
levels = c("00:00:00", "01:00:00", "02:00:00", "03:00:00", | |
"04:00:00", "05:00:00", "06:00:00", "07:00:00", | |
"08:00:00", "09:00:00", "10:00:00", "11:00:00", | |
"12:00:00", "13:00:00", "14:00:00", "15:00:00", | |
"16:00:00", "17:00:00", "18:00:00", "19:00:00", | |
"20:00:00", "21:00:00", "22:00:00", "23:00:00"), | |
labels = c(paste0(seq(0, 23, 1), "h"))) | |
contagem %>% | |
ggplot(aes(horario_tweet, percentual)) + | |
geom_bar(stat = "identity") + | |
scale_x_discrete(breaks = c(paste0(seq(0, 22, 2), "h"))) + | |
#scale_y_continuous(limits = c(0,9), breaks = seq(0,9,1)) + | |
theme_minimal() + | |
theme(plot.title = element_text(hjust = 0.5, size = 12), | |
plot.caption = element_text(hjust = 0.5, size = 9), | |
axis.title.x = element_text(hjust = 0.5, size = 10), | |
axis.title.y = element_text(hjust = 0.5, size = 10)) + | |
labs(title = "Horários de tweets que contêm \"supermercado+estou\"", | |
caption = "Fonte: 21 tweets em português postados entre os\ndias 21 e 27 de março (coletados com o pacote rtweet)", | |
x = "Horário da postagem (Brasília)", y = "Percentual do total de tweets") | |
ggsave("supermercado.jpeg", dpi = 300, width = 6, height = 4) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment