# Basic knitr options library(knitr) opts_chunk$set(comment = NA, echo = FALSE, warning = FALSE, message = FALSE, error = TRUE, cache = FALSE, fig.path = 'figures/')
# Libraries library(vilaweb) library(rtweet) library(tidyverse) library(databrew) library(translateR) library(sentimentr) # https://github.com/trinker/sentimentr
Os presento a mi nuevo amigo, @venciendoen1714. Es una cuenta falsa como tantas otras (asunto no tan interesante), pero hay unos detalles interesantes que nos enseñan como funcionan estas cuentas y por qué. (Hilo)
Su nombre de usuario es "Os vencimos en 1714 y ahora también". Es una cuenta pirómana. Su razon de ser es insultar y crear tensions.
# Define function for improving timeline improve_timeline <- function(tmls){ tmls$time_only <- sapply(strsplit(substr(tmls$created_at, 11,19), ":"), function(x){as.numeric(x) %*% c(3600, 60, 1)}) tmls$time_only <- tmls$time_only / 3600 tmls$date <- as.Date(cut(tmls$created_at, 'day')) tmls$hour <- as.POSIXct(cut(tmls$created_at, 'hour')) return(tmls) } # # Get most recent tweets from ciudadanos # tmls <- get_timelines(c('venciendoen1714'), n = 3200) # guy <- lookup_users(users = tmls$user_id[1]) # tmls <- improve_timeline(tmls) # pd <- tmls %>% # mutate(hour = as.POSIXct(cut(created_at, 'hour'))) %>% # group_by(hour) %>% # tally # # ggplot(data = pd, # aes(x = hour, # y = n)) + # geom_bar(stat = 'identity') + # theme(axis.text.x = element_text(angle = 90)) # # library(ggridges) # ggplot(data = tmls, # aes(x = time_only, # y = as.factor(date))) + # geom_density_ridges() + # theme_minimal()
file_name <- 'no_hay_presos.RDatas.RData' if(!file_name %in% dir()){ rt <- search_tweets( '"No hay presos políticos en España"', n = 1000000, include_rts = F, retryonratelimit = TRUE ) save(rt, file = file_name) } else { load(file_name) } file_name <- 'comandos.RData' if(!file_name %in% dir()){ cs <- search_tweets( '"comandos separatistas"', n = 1000000, include_rts = T, retryonratelimit = TRUE ) save(cs, file = file_name) } else { load(file_name) } file_name <- 'presos.RData' if(!file_name %in% dir()){ pp <- search_tweets( '"presos polítics"', n = 1000000, include_rts = T, retryonratelimit = TRUE ) save(pp, file = file_name) } else { load(file_name) } file_name <- 'vaga.RData' if(!file_name %in% dir()){ va <- search_tweets( '"vaga de fam"', n = 1000000, include_rts = T, retryonratelimit = TRUE ) save(va, file = file_name) } else { load(file_name) } if(!'data.RData' %in% dir()){ data <- list(va, cs, rt) data_names <- c('Vaga de fam', 'Comandos separatistas', 'No hay presos políticos en España') out_list <- list() guys_list <- list() tl_list <- list() for(i in 1:length(data)){ message(data_names[i]) the_data <- data[[i]] out_list[[i]] <- the_data %>% mutate(source = data_names[i]) message('---getting users') bots <- lookup_users(users = unique(the_data$user_id)) %>% mutate(source = data_names[i]) guys_list[[i]] <- bots bots <- bots %>% filter(followers_count <= 10) message('---getting tweets') # i = 4 here: # save(bots, the_data, out_list, guys_list, tl_list, file = 'temp.RData') tls <- get_timelines(bots$screen_name, n = 3200) %>% mutate(source = data_names[i]) tl_list[[i]] <- tls } tweets <- bind_rows(out_list) people <- bind_rows(guys_list) people_tls <- bind_rows(tl_list) save(tweets, people, people_tls, file = 'data.RData') } else { load('data.RData') } out <- bind_rows() guys <- lookup_users(users = unique(cs$user_id)) # Keep those with fewer than 10 followers bots <- guys %>% filter(followers_count < 10) # Get the timelines of the bots bot_tmls <- get_timelines(bots$screen_name, n = 3200) bot_tmls <- improve_timeline(bot_tmls) ggplot(data = bot_tmls %>% filter(date >= '2017-01-01'), aes(x = time_only, # y = as.factor(date), y = date)) + geom_point(size = 0.2, aes(color = screen_name)) + # geom_density_ridges() + theme_minimal() + theme(legend.position = 'none') # facet_wrap(~screen_name, # scales = 'free') # Look at created_at, account_lang, # profile_image_url: http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.