a. ¿Cuáles son los mensajes con más repercusión? ¿Qué dicen?

b. ¿En qué momento del día se realiza la mayor cantidad de tweets? Graficar.

c. ¿Cómo se distribuye la popularidad de los usuarios? ¿Quiénes son los 5 que más seguidores tienen? Graficar.

d. Aislando los tweets que poseen coordenadas geográficas (lat y long), crear mapas que muestren posición de los tweets y cantidad de seguidores del usuario que tuitea.

Mapear Tweets Cargo las librerias y los paquetes necesarios

install.packages(“leaflet”) install.packages(“rtweet”) install.packages(“ggmap”)

Llamo a las librerias necesarias library(tidyverse) library(leaflet) library(rtweet) library(ggmap)

library(rtweet)
## Warning: package 'rtweet' was built under R version 3.6.1
library(tidyverse)
## Registered S3 method overwritten by 'rvest':
##   method            from
##   read_xml.response xml2
## -- Attaching packages --------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.2.0       v purrr   0.3.2  
## v tibble  2.1.1       v dplyr   0.8.0.1
## v tidyr   0.8.3       v stringr 1.4.0  
## v readr   1.3.1       v forcats 0.4.0
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter()  masks stats::filter()
## x purrr::flatten() masks rtweet::flatten()
## x dplyr::lag()     masks stats::lag()

Cargo el csv de los tweets

tweetsBA <- read.csv("~/MEU/MU115 - CIencia de Datos II/tweetsBA.csv", encoding = "UTF-8")
users_data(tweetsBA) %>% head()
##        user_id    screen_name
## 1 1.690628e+08        Mar_221
## 2 1.043183e+09         roiggi
## 3 1.161094e+09   VivirporBoca
## 4 3.417911e+08  carlbonifatti
## 5 8.435612e+17      tapochski
## 6 4.015059e+08 victorhugocom1
##                                                       name
## 1                                                      Mar
## 2                                                     gise
## 3                                          Ulises Chaparro
## 4 Carl Bonifatti <U+0001F331> SOS <U+0001F1FB><U+0001F1EA>
## 5                                            Maga campeona
## 6                                          @victorhugo.com
##                         location
## 1                   Buenos Aires
## 2                   Buenos Aires
## 3         Castelar, Buenos Aires
## 4        Buenos Aires, Argentina
## 5 Florencio Varela, Buenos aires
## 6        Buenos Aires, Argentina
##                                                                                                                                     description
## 1 Abogada, no como la kuatrera de Tolosa y por lo mismo no ando con vueltas. El mas degradante invento del siglo es lo “políticamente correcto”
## 2                                                                                                           Ituzaingo y Moron....mis dos amores
## 3                                         Hincha del Boca de Macri. Estudiante Veterinaria UBA. No vuelven más. Que boludos son los comunistas.
## 4                                                          <U+260E> 0800-555-5065 las 24 hs. si ves a alguien organizando saqueos o disturbios.
## 5                                               Fotógrafa, hincha de Racing, marxista hija del argentinazo.\nPortfolio: https://t.co/xxQhO9s03d
## 6                                                                                                                                              
##                       url protected followers_count friends_count
## 1                             FALSE            1528           788
## 2                             FALSE             402          1044
## 3                             FALSE            7912          3390
## 4 https://t.co/UCicQfhWu5     FALSE           75346         39261
## 5 https://t.co/dZYNvI4xs5     FALSE            1964           489
## 6                             FALSE              20           132
##   listed_count statuses_count favourites_count   account_created_at
## 1           23          70450            30659 2010-07-21T13:09:22Z
## 2            1          14961             8655 2012-12-28T21:24:56Z
## 3            7          20148            12781 2013-02-08T20:10:42Z
## 4          281         134387           142941 2011-07-24T23:46:39Z
## 5            9          26445            23227 2017-03-19T20:33:51Z
## 6            0           1579              418 2011-10-30T17:04:25Z
##   verified             profile_url                profile_expanded_url
## 1    FALSE                                                            
## 2    FALSE                                                            
## 3    FALSE                                                            
## 4    FALSE https://t.co/UCicQfhWu5 https://carlbonifatti.wordpress.com
## 5    FALSE https://t.co/dZYNvI4xs5     http://instagram.com/mdefelippe
## 6    FALSE                                                            
##   account_lang
## 1           NA
## 2           NA
## 3           NA
## 4           NA
## 5           NA
## 6           NA
##                                                    profile_banner_url
## 1          https://pbs.twimg.com/profile_banners/169062778/1489984379
## 2         https://pbs.twimg.com/profile_banners/1043183088/1396838777
## 3         https://pbs.twimg.com/profile_banners/1161094200/1385598221
## 4          https://pbs.twimg.com/profile_banners/341791093/1446999637
## 5 https://pbs.twimg.com/profile_banners/843561175778508800/1550706016
## 6          https://pbs.twimg.com/profile_banners/401505895/1506966552
##                              profile_background_url
## 1  http://abs.twimg.com/images/themes/theme1/bg.png
## 2 http://abs.twimg.com/images/themes/theme11/bg.gif
## 3 http://abs.twimg.com/images/themes/theme18/bg.gif
## 4 http://abs.twimg.com/images/themes/theme14/bg.gif
## 5                                                  
## 6  http://abs.twimg.com/images/themes/theme1/bg.png
##                                                             profile_image_url
## 1 http://pbs.twimg.com/profile_images/1088234307737567232/y6vbDrZ0_normal.jpg
## 2 http://pbs.twimg.com/profile_images/472898913926516736/Pe00nWbu_normal.jpeg
## 3 http://pbs.twimg.com/profile_images/1142950745471356930/fVT_exwF_normal.png
## 4  http://pbs.twimg.com/profile_images/647980381363412992/IXcP9pGC_normal.jpg
## 5 http://pbs.twimg.com/profile_images/1151258915151196167/-uiU2hdN_normal.jpg
## 6  http://pbs.twimg.com/profile_images/914909214308519938/_zXonKUR_normal.jpg
names(tweetsBA)
##  [1] "user_id"                 "status_id"              
##  [3] "created_at"              "screen_name"            
##  [5] "text"                    "source"                 
##  [7] "display_text_width"      "reply_to_status_id"     
##  [9] "reply_to_user_id"        "reply_to_screen_name"   
## [11] "is_quote"                "is_retweet"             
## [13] "favorite_count"          "retweet_count"          
## [15] "quote_count"             "reply_count"            
## [17] "hashtags"                "symbols"                
## [19] "urls_url"                "urls_t.co"              
## [21] "urls_expanded_url"       "media_url"              
## [23] "media_t.co"              "media_expanded_url"     
## [25] "media_type"              "ext_media_url"          
## [27] "ext_media_t.co"          "ext_media_expanded_url" 
## [29] "ext_media_type"          "mentions_user_id"       
## [31] "mentions_screen_name"    "lang"                   
## [33] "quoted_status_id"        "quoted_text"            
## [35] "quoted_created_at"       "quoted_source"          
## [37] "quoted_favorite_count"   "quoted_retweet_count"   
## [39] "quoted_user_id"          "quoted_screen_name"     
## [41] "quoted_name"             "quoted_followers_count" 
## [43] "quoted_friends_count"    "quoted_statuses_count"  
## [45] "quoted_location"         "quoted_description"     
## [47] "quoted_verified"         "retweet_status_id"      
## [49] "retweet_text"            "retweet_created_at"     
## [51] "retweet_source"          "retweet_favorite_count" 
## [53] "retweet_retweet_count"   "retweet_user_id"        
## [55] "retweet_screen_name"     "retweet_name"           
## [57] "retweet_followers_count" "retweet_friends_count"  
## [59] "retweet_statuses_count"  "retweet_location"       
## [61] "retweet_description"     "retweet_verified"       
## [63] "place_url"               "place_name"             
## [65] "place_full_name"         "place_type"             
## [67] "country"                 "country_code"           
## [69] "status_url"              "name"                   
## [71] "location"                "description"            
## [73] "url"                     "protected"              
## [75] "followers_count"         "friends_count"          
## [77] "listed_count"            "statuses_count"         
## [79] "favourites_count"        "account_created_at"     
## [81] "verified"                "profile_url"            
## [83] "profile_expanded_url"    "account_lang"           
## [85] "profile_banner_url"      "profile_background_url" 
## [87] "profile_image_url"       "lon"                    
## [89] "lat"
options(scipen = 20)
ggplot(tweetsBA) +
    geom_histogram(aes(x = followers_count))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Top 5 de ,los que mas seguidores tienen:

tweetsBA %>% 
    top_n(5, followers_count) %>% 
    arrange(desc(followers_count)) %>% 
    select(screen_name, followers_count, location, text)
##      screen_name followers_count                location
## 1      ESPNFCarg          447378 Buenos Aires, Argentina
## 2      Lubertino          121297            Buenos Aires
## 3  carlbonifatti           75346 Buenos Aires, Argentina
## 4 CELS_Argentina           69452 Buenos Aires, Argentina
## 5    rayovirtual           47118 Buenos Aires, Argentina
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           text
## 1                                                                                                                                                                                                                                                                                                                                                            #Video | #Ligue1xESPN <U+0001F1EB><U+0001F1F7>\n\nNO LE GUSTÓ NADA\n\nAndré Villas-Boas se mostró enojadísimo por la decisión de Benedetto de agarrar el penal que terminó malogrando.\n\nhttps://t.co/btxcRqIjXZ
## 2                                                                                                                                                                                                                                                                                                                                                                              #Ahora en #BarrioCarrillo #Comuna8 en reunión con referentes de villas y @UNICEFargentina en diálogo sobre #violenciainstitucional en relación a #niñes y #adolescentes https://t.co/4Pyo5QomXr
## 3                                                                                                                                                                                                                                                                                                                                                                                                                Cristóbal López con el guiño de Cristina y Máximo financia un estallido social, inyectando dinero en las Villas para movilizar a sus habitantes. #PorotaTajai
## 4 <U+0001D5D6><U+0001D5EE><U+0001D600><U+0001D5EE><U+0001D600> <U+0001D600><U+0001D5F6><U+0001D5FB> <U+0001D5F4><U+0001D5F2><U+0001D5FB><U+0001D601><U+0001D5F2>/ <U+0001D5DA><U+0001D5F2><U+0001D5FB><U+0001D601><U+0001D5F2> <U+0001D600><U+0001D5F6><U+0001D5FB> <U+0001D5F0><U+0001D5EE><U+0001D600><U+0001D5EE><U+0001D600>\nSegún datos oficiales el 9,2% de las viviendas de la ciudad de Bs. As están vacías.\n\n<U+2757><U+FE0F>138.328 casas y departamentos.\n\nMientras que:\n-300.000 personas viven en villas y asentamientos\n-7500 están en situación de calle
## 5                                                                                                                                                                                                                                                                               @Ricardo_blogger No. Por un lado quieren satisfacer al cliente (y muchos trabajan para Alberto), pero por otro quieren acertar porque pierden prestigio y trabajo futuro.\nEs que usar el teléfono es más barato que mandar gente a las villas y barrios pobres (mucho más barato) y eso pesa.

Me quedo con los tweets originales, eliminando los retweets

ggplot(filter(tweetsBA, !is_retweet))+
    geom_histogram(aes(x = retweet_count))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

el que mas seguidores tiene:

tweetsBA %>% 
    filter(!is_retweet) %>% 
    filter(retweet_count == max(retweet_count)) %>% 
    select(screen_name, retweet_count, followers_count, location, text)
##   screen_name retweet_count followers_count                location
## 1    belumita           739            8049 Buenos Aires, Argentina
##                                                                                                                                                                                                                                                           text
## 1 USTEDES ENTIENDEN QUE VA A MANEJAR LA PROVINCIA (centro de pobreza, corrupción y villas) UN TIPO QUE DICE QUE \n\n“La inflación NO ES un fenómeno monetario” ??????\n\nY quien manejaba LA MATANZA, irónicamente el centro de homicidios de Bs As. Infierno.

Distribucion horaria de los tweets

library(lubridate)
## Warning: package 'lubridate' was built under R version 3.6.1
## 
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
## 
##     date
tweetsBA <- tweetsBA %>%
  mutate(created_at = ymd_hms(created_at))


tweetsBA %>% 
  group_by(hour = hour(created_at)) %>% 
  summarise(total = n()) %>% 
  ggplot() +
  geom_path(aes(x = hour, y = total))

tweetsBA %>% 
  group_by(dia_hora = floor_date(created_at, "hour")) %>% 
  summarise(total = n()) %>% 
  ggplot() +
  geom_path(aes(x = dia_hora, y = total))

library(ggmap)
## Warning: package 'ggmap' was built under R version 3.6.1
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.

Mapeamos los tweets

coordenadasBA <- function(campo_coordenadas) {
    extraer_coordenadas <- function(lista_coords) {
        data_frame(lon = lista_coords[1],
                   lat = lista_coords[2])
    }
    
    map_df(campo_coordenadas, extraer_coordenadas)
}

No me permite hacer nada, porque los tweets no tienen coordenadas…

tweetsBA_geo <- tweetsBA %>% 
    filter(!is.na(lat), !is.na(lon))