Instalación 📩📦:

  1. Instalamos el paquete y otras librerias necesarias:
library(devtools)
#> Loading required package: usethis
#install_github("guadag12/politicxsentwitteR", force=T)
library(politicxsentwitteR)

Descargá la data de politicxs 👩📚:

  1. Lista de usuarios que contiene Politicxs en twitter

Podemos ver la lista que tenemos de funcionarios con politicxs_data:

head(politicxs_data)
#> # A tibble: 6 x 9
#>   user_id  screen_name  category  description     name    gender followers_count
#>   <chr>    <chr>        <chr>     <chr>           <chr>   <chr>            <dbl>
#> 1 1204088… A_Carambia   deputies  "Diputado Naci… Antoni… M                  183
#> 2 8417571… Adriana_Rua… deputies  "Vecina de Deá… Adrian… F                 1206
#> 3 1277698… AgenciaAfi   national… "Cuenta oficia… Agenci… ND                2508
#> 4 1661771… Agricultura… national… "Cuenta oficia… Minist… ND              162332
#> 5 1752732… AgustinLaje  others    "Escritor. Lic… Agustí… M               457882
#> 6 39276894 AidaAyala    deputies  "Diputada Naci… Aída A… F                 8360
#> # … with 2 more variables: profile_image_url <chr>, country <chr>

Timeline de usuarios 📲:

    1. Podemos descargar sobre un usuario determinado con la función get_timeline_data
timeline_af <- get_timeline_data("alferdez")
head(timeline_af, 2)
#>     user_id           status_id          created_at screen_name
#> 1 149991703 1132431445392265217 2019-05-25 23:41:10    alferdez
#> 2 149991703 1132445599293464577 2019-05-26 00:37:25    alferdez
#>                                                                                                                                                                                                                                                                      text
#> 1                                                                                                                                                             Desatemos la esperanza.\nVamos a volver para ser mejores.\n#EntreTodos\n#EntreTodas https://t.co/saKlixKj59
#> 2 “Con Néstor entramos al mismo laberinto que tenemos que entrar ahora el  diez de Diciembre. Yo estuve en ese laberinto y supe cómo salir. Vamos a salir todos trabajando codo a codo” @alferdez @CFKArgentina #EsConTodos #EsConTodas #25deMayo https://t.co/GPovmtEZI7
#>               source is_quote is_retweet favorite_count retweet_count lang
#> 1 Twitter for iPhone    FALSE      FALSE           8286          1847   es
#> 2 Twitter for iPhone    FALSE       TRUE              0           391   es
#>                                                status_url              name
#> 1 https://twitter.com/alferdez/status/1132431445392265217 Alberto Fernández
#> 2 https://twitter.com/alferdez/status/1132445599293464577 Alberto Fernández
#>     mentions_user_id mentions_screen_name   retweet_status_id
#> 1               <NA>                 <NA>                <NA>
#> 2 981230259533221888          GrupoCallao 1132440578191437825
#>                                                                                                                                                                                                                                                              retweet_text
#> 1                                                                                                                                                                                                                                                                    <NA>
#> 2 “Con Néstor entramos al mismo laberinto que tenemos que entrar ahora el  diez de Diciembre. Yo estuve en ese laberinto y supe cómo salir. Vamos a salir todos trabajando codo a codo” @alferdez @CFKArgentina #EsConTodos #EsConTodas #25deMayo https://t.co/GPovmtEZI7
#>    retweet_created_at      retweet_source retweet_favorite_count
#> 1                <NA>                <NA>                   <NA>
#> 2 2019-05-26 00:17:28 Twitter for Android                   1388
#>   retweet_retweet_count    retweet_user_id retweet_screen_name retweet_name
#> 1                  <NA>               <NA>                <NA>         <NA>
#> 2                   391 981230259533221888         GrupoCallao Grupo Callao
#>   retweet_followers_count retweet_friends_count retweet_statuses_count
#> 1                    <NA>                  <NA>                   <NA>
#> 2                   17745                   242                   1619
#>   retweet_location retweet_description retweet_verified reply_to_status_id
#> 1             <NA>                <NA>             <NA>               <NA>
#> 2                                                 FALSE               <NA>
#>   reply_to_user_id reply_to_screen_name urls_url urls_t_co
#> 1             <NA>                 <NA>     <NA>      <NA>
#> 2             <NA>                 <NA>     <NA>      <NA>
  1. E incluso saber cuándo fue que más twitteó:
library(tidyverse)
#> ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
#> ✓ ggplot2 3.3.3     ✓ purrr   0.3.4
#> ✓ tibble  3.1.2     ✓ dplyr   1.0.7
#> ✓ tidyr   1.1.2     ✓ stringr 1.4.0
#> ✓ readr   1.4.0     ✓ forcats 0.5.0
#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
#> x dplyr::filter() masks stats::filter()
#> x dplyr::lag()    masks stats::lag()
library(hrbrthemes)
#> NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
#>       Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
#>       if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow

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()

  1. 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)
#>    user_id           status_id          created_at  screen_name
#> 1 54414081 1000000521158230016 2018-05-25 13:07:58 PatoBullrich
#> 2 54414081 1000000521158234114 2018-05-25 13:07:58 PatoBullrich
#>                                                                                                                                                             text
#> 1 Feliz #DíaDeLaPatria.\nQuiero reconocer a todos los que hoy están cuidando a los argentinos en cada rincón de nuestro país.\n#25DeMayo https://t.co/vu2DSW9GvG
#> 2 Feliz #DíaDeLaPatria.\nQuiero reconocer a todos los que hoy están cuidando a los argentinos en cada rincón de nuestro país.\n#25DeMayo https://t.co/vu2DSW9GvG
#>                source is_quote is_retweet favorite_count retweet_count lang
#> 1 Twitter for Android    FALSE      FALSE           3915          1264   es
#> 2 Twitter for Android    FALSE      FALSE           3928          1277   es
#>                                                    status_url              name
#> 1 https://twitter.com/PatoBullrich/status/1000000521158234114 Patricia Bullrich
#> 2 https://twitter.com/PatoBullrich/status/1000000521158234114 Patricia Bullrich
#>   mentions_user_id mentions_screen_name reply_to_status_id reply_to_user_id
#> 1             <NA>                 <NA>               <NA>             <NA>
#> 2             <NA>                 <NA>               <NA>             <NA>
#>   reply_to_screen_name retweet_status_id retweet_text retweet_created_at
#> 1                 <NA>              <NA>         <NA>               <NA>
#> 2                 <NA>              <NA>         <NA>               <NA>
#>   retweet_source retweet_favorite_count retweet_retweet_count retweet_user_id
#> 1           <NA>                   <NA>                  <NA>            <NA>
#> 2           <NA>                   <NA>                  <NA>            <NA>
#>   retweet_screen_name retweet_name retweet_followers_count
#> 1                <NA>         <NA>                    <NA>
#> 2                <NA>         <NA>                    <NA>
#>   retweet_friends_count retweet_statuses_count retweet_location
#> 1                  <NA>                   <NA>             <NA>
#> 2                  <NA>                   <NA>             <NA>
#>   retweet_description retweet_verified urls_url urls_t_co
#> 1                <NA>             <NA>     <NA>      <NA>
#> 2                <NA>             <NA>     <NA>      <NA>
  1. 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()
#> `summarise()` has grouped output by 'date'. You can override using the `.groups` argument.

Friends & Followers 👥:

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)
#>   screen_name       date followers_count friends_count listed_count
#> 1  mariuvidal 2020-12-25         1623740           558         1947
#> 2  mariuvidal 2021-02-11         1623073           556         1956
#>   statuses_count favourites_count
#> 1           7516              487
#> 2           7516              487

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") 

Redes 🤖🕸️

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)
#>       month_year             user_id     retweet_user_id value
#> 51509 2021-01-31           105180935            54414081     1
#> 51527 2021-01-31 1095773453855137794 1095773453855137794    10

5.b. También podemos hacer una nube con la info obtenida:

library(igraph)
#> 
#> Attaching package: 'igraph'
#> The following objects are masked from 'package:dplyr':
#> 
#>     as_data_frame, groups, union
#> The following objects are masked from 'package:purrr':
#> 
#>     compose, simplify
#> The following object is masked from 'package:tidyr':
#> 
#>     crossing
#> The following object is masked from 'package:tibble':
#> 
#>     as_data_frame
#> The following objects are masked from 'package:stats':
#> 
#>     decompose, spectrum
#> The following object is masked from 'package:base':
#> 
#>     union
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()
#> Joining, by = "user_id"

p <- simpleNetwork(others_network, height="100px", width="100px")
p

Warnings ⚠:

  • La data recolectada puede estar incompleta, ya que la recolección comenzó en febrero 2021 y la API de Twitter devuelve los últimos 3200 tweets de ese usuario. En este sentido, si el usuario redactó más de 3200 tweets, muchos de ellos no van a poder ser capturados por este paquete.