knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
#install_github("guadag12/politicxsentwitteR", force=T) library(politicxsentwitteR)
Podemos ver la lista que tenemos de funcionarios con politicxs_data:
head(politicxs_data)
timeline_af <- get_timeline_data("alferdez") head(timeline_af, 2)
b. E incluso saber cuándo fue que más twitteó:
library(tidyverse) library(hrbrthemes) timeline_af %>% group_by(date=as.Date(created_at)) %>% summarise(value = n()) %>% ggplot( aes(x=date, y=value)) + geom_area(fill="#dbb012", alpha=0.5) + geom_line(color="#dbb012") + ggtitle("Tweets emitidos por @alferdez") + theme_ipsum()
c. Podemos hacerlo comparando la cantidad de tweets de más de un usuario:
timeline_pb_mm <- get_timeline_data(screen.name = c("PatoBullrich", "mauriciomacri")) head(timeline_pb_mm, 2)
d. Además, podemos graficar en qué periodos de tiempos más twittearon ambos:
timeline_pb_mm %>% group_by(date=as.Date(created_at), screen_name) %>% summarise(value = n()) %>% ggplot( aes(x=date, y=value)) + geom_area(aes(fill = screen_name), alpha=0.5) + geom_line(aes(color = screen_name)) + ggtitle("Tweets emitidos por @mauriciomacri y @PatoBullrich") + theme_ipsum()
4.a. Podemos ver cuántos amigos tiene cada uno con la función get_friends_followers:
foll_friends_mv_hl <- get_friends_followers(screen.name = c( "mariuvidal", "horaciorlarreta")) head(foll_friends_mv_hl, 2)
4.b. Tambien podemos generar graficos según el tipo de interacción:
foll_friends_mv_hl %>% ggplot() + geom_line(aes(x=as.Date(date), y=as.numeric(followers_count), color=screen_name)) + theme_bw() + scale_color_manual(values = c("#ffbb00", "#ae45ff")) + labs( x = "Fecha", y = "Cantidad", title = "Evolución de followers de @mariuvidal y @horaciorlarreta")
5.a. Podemos obtener la data de redes (para un periodo de tiempo y que se actualiza de manera mensual):
others_network <- get_network_data(category = "others") head(others_network, 2)
5.b. También podemos hacer una nube con la info obtenida:
library(igraph) library(networkD3) others_network <- others_network %>% left_join(politicxs_data) %>% select(screen_name_from = screen_name, retweet_user_id, value) %>% left_join(politicxs_data, by = c("retweet_user_id"= "user_id")) %>% select(from=screen_name_from, to = screen_name, value) %>% drop_na() p <- simpleNetwork(others_network, height="100px", width="100px") p
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.