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()
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.
load(url("https://bitsandbricks.github.io/data/tweets_transporte.RData"))
coordenadas <- function(campo_coordenadas) {
extraer_coordenadas <- function(lista_coords) {
data_frame(lon = lista_coords[1],
lat = lista_coords[2])
}
map_df(campo_coordenadas, extraer_coordenadas)
}
tweets <- tweets_transporte %>%
cbind(coordenadas(tweets_transporte$coords_coords)) %>%
select(-geo_coords, -coords_coords, -bbox_coords)
## Warning: `data_frame()` is deprecated, use `tibble()`.
## This warning is displayed once per session.
tweets_geo <- tweets %>%
filter(!is.na(lat), !is.na(lon))
users_data(tweets) %>% head()
## user_id screen_name name
## 1 2196425515 FlorentinoMaru Maru Florentino
## 10 237046674 Palauraa Laura Palau
## 19 465699640 Juli_Schreiber Juli Sch
## 28 143913975 rielesnoticias Rieles Multimedio
## 34 143913975 rielesnoticias Rieles Multimedio
## 46 954022826 Peruussi Peruuuuussi <U+0001F49A>
## location
## 1 Quilmes
## 10 Buenos Aires, Argentina
## 19 Buenos Aires, Argentina
## 28 Buenos Aires
## 34 Buenos Aires
## 46 Buenos Aires, Argentina
## description
## 1 Los sueños pueden hacerse realidad! Tía las 24 horas. Viajera apasionada. Pensadora ecléctica. Mono de fuego a morir!
## 10 23 | Lic. en Comunicación Social | #Cultura y #LadoNerd en @Corriendolavoz_ <U+270F> Operadora en @RadioHexa <U+0001F4FB><U+0001F3B6> Feminista <U+0001F49C><U+0001F49A> Según el Sombrero, soy Gryffindor <U+0001F981>
## 19
## 28 Rieles es el multimedio periodístico especializado en el sector ferroviario de toda América Latina. #ferrocarriles
## 34 Rieles es el multimedio periodístico especializado en el sector ferroviario de toda América Latina. #ferrocarriles
## 46 <U+0001F49A><U+0001F49A><U+0001F49A>19.
## url protected followers_count friends_count
## 1 <NA> FALSE 141 134
## 10 https://t.co/CS3AuCOMyL FALSE 397 380
## 19 https://t.co/Y3chNYR5al FALSE 257 507
## 28 http://t.co/WbB7MDgdth FALSE 2618 545
## 34 http://t.co/WbB7MDgdth FALSE 2618 545
## 46 <NA> FALSE 1023 2005
## listed_count statuses_count favourites_count account_created_at
## 1 1 9441 567 2013-11-15 18:28:49
## 10 5 14505 12497 2011-01-11 23:32:53
## 19 0 1366 1034 2012-01-16 17:00:11
## 28 43 14872 387 2010-05-14 19:39:11
## 34 43 14872 387 2010-05-14 19:39:11
## 46 3 20049 23792 2012-11-17 17:48:29
## verified profile_url profile_expanded_url
## 1 FALSE <NA> <NA>
## 10 FALSE https://t.co/CS3AuCOMyL http://www.corriendolavoz.com.ar
## 19 FALSE https://t.co/Y3chNYR5al http://instagram.com/julietaschreiber
## 28 FALSE http://t.co/WbB7MDgdth http://www.rieles.com
## 34 FALSE http://t.co/WbB7MDgdth http://www.rieles.com
## 46 FALSE <NA> <NA>
## account_lang
## 1 es
## 10 es
## 19 es
## 28 es
## 34 es
## 46 es
## profile_banner_url
## 1 https://pbs.twimg.com/profile_banners/2196425515/1460736261
## 10 https://pbs.twimg.com/profile_banners/237046674/1485904309
## 19 https://pbs.twimg.com/profile_banners/465699640/1385596210
## 28 https://pbs.twimg.com/profile_banners/143913975/1515437766
## 34 https://pbs.twimg.com/profile_banners/143913975/1515437766
## 46 https://pbs.twimg.com/profile_banners/954022826/1520471336
## profile_background_url
## 1 http://abs.twimg.com/images/themes/theme10/bg.gif
## 10 http://abs.twimg.com/images/themes/theme11/bg.gif
## 19 http://abs.twimg.com/images/themes/theme18/bg.gif
## 28 http://abs.twimg.com/images/themes/theme7/bg.gif
## 34 http://abs.twimg.com/images/themes/theme7/bg.gif
## 46 http://abs.twimg.com/images/themes/theme9/bg.gif
## profile_image_url
## 1 http://pbs.twimg.com/profile_images/540245595324047360/-1kt7KC__normal.jpeg
## 10 http://pbs.twimg.com/profile_images/1021518022245277704/lOxB60ZS_normal.jpg
## 19 http://pbs.twimg.com/profile_images/1014683911606210560/NueFOIBd_normal.jpg
## 28 http://pbs.twimg.com/profile_images/958756679272861696/j0a7gd1s_normal.jpg
## 34 http://pbs.twimg.com/profile_images/958756679272861696/j0a7gd1s_normal.jpg
## 46 http://pbs.twimg.com/profile_images/1007115739252207616/WvBY1e7V_normal.jpg
users_data(tweets) %>% head()
## user_id screen_name name
## 1 2196425515 FlorentinoMaru Maru Florentino
## 10 237046674 Palauraa Laura Palau
## 19 465699640 Juli_Schreiber Juli Sch
## 28 143913975 rielesnoticias Rieles Multimedio
## 34 143913975 rielesnoticias Rieles Multimedio
## 46 954022826 Peruussi Peruuuuussi <U+0001F49A>
## location
## 1 Quilmes
## 10 Buenos Aires, Argentina
## 19 Buenos Aires, Argentina
## 28 Buenos Aires
## 34 Buenos Aires
## 46 Buenos Aires, Argentina
## description
## 1 Los sueños pueden hacerse realidad! Tía las 24 horas. Viajera apasionada. Pensadora ecléctica. Mono de fuego a morir!
## 10 23 | Lic. en Comunicación Social | #Cultura y #LadoNerd en @Corriendolavoz_ <U+270F> Operadora en @RadioHexa <U+0001F4FB><U+0001F3B6> Feminista <U+0001F49C><U+0001F49A> Según el Sombrero, soy Gryffindor <U+0001F981>
## 19
## 28 Rieles es el multimedio periodístico especializado en el sector ferroviario de toda América Latina. #ferrocarriles
## 34 Rieles es el multimedio periodístico especializado en el sector ferroviario de toda América Latina. #ferrocarriles
## 46 <U+0001F49A><U+0001F49A><U+0001F49A>19.
## url protected followers_count friends_count
## 1 <NA> FALSE 141 134
## 10 https://t.co/CS3AuCOMyL FALSE 397 380
## 19 https://t.co/Y3chNYR5al FALSE 257 507
## 28 http://t.co/WbB7MDgdth FALSE 2618 545
## 34 http://t.co/WbB7MDgdth FALSE 2618 545
## 46 <NA> FALSE 1023 2005
## listed_count statuses_count favourites_count account_created_at
## 1 1 9441 567 2013-11-15 18:28:49
## 10 5 14505 12497 2011-01-11 23:32:53
## 19 0 1366 1034 2012-01-16 17:00:11
## 28 43 14872 387 2010-05-14 19:39:11
## 34 43 14872 387 2010-05-14 19:39:11
## 46 3 20049 23792 2012-11-17 17:48:29
## verified profile_url profile_expanded_url
## 1 FALSE <NA> <NA>
## 10 FALSE https://t.co/CS3AuCOMyL http://www.corriendolavoz.com.ar
## 19 FALSE https://t.co/Y3chNYR5al http://instagram.com/julietaschreiber
## 28 FALSE http://t.co/WbB7MDgdth http://www.rieles.com
## 34 FALSE http://t.co/WbB7MDgdth http://www.rieles.com
## 46 FALSE <NA> <NA>
## account_lang
## 1 es
## 10 es
## 19 es
## 28 es
## 34 es
## 46 es
## profile_banner_url
## 1 https://pbs.twimg.com/profile_banners/2196425515/1460736261
## 10 https://pbs.twimg.com/profile_banners/237046674/1485904309
## 19 https://pbs.twimg.com/profile_banners/465699640/1385596210
## 28 https://pbs.twimg.com/profile_banners/143913975/1515437766
## 34 https://pbs.twimg.com/profile_banners/143913975/1515437766
## 46 https://pbs.twimg.com/profile_banners/954022826/1520471336
## profile_background_url
## 1 http://abs.twimg.com/images/themes/theme10/bg.gif
## 10 http://abs.twimg.com/images/themes/theme11/bg.gif
## 19 http://abs.twimg.com/images/themes/theme18/bg.gif
## 28 http://abs.twimg.com/images/themes/theme7/bg.gif
## 34 http://abs.twimg.com/images/themes/theme7/bg.gif
## 46 http://abs.twimg.com/images/themes/theme9/bg.gif
## profile_image_url
## 1 http://pbs.twimg.com/profile_images/540245595324047360/-1kt7KC__normal.jpeg
## 10 http://pbs.twimg.com/profile_images/1021518022245277704/lOxB60ZS_normal.jpg
## 19 http://pbs.twimg.com/profile_images/1014683911606210560/NueFOIBd_normal.jpg
## 28 http://pbs.twimg.com/profile_images/958756679272861696/j0a7gd1s_normal.jpg
## 34 http://pbs.twimg.com/profile_images/958756679272861696/j0a7gd1s_normal.jpg
## 46 http://pbs.twimg.com/profile_images/1007115739252207616/WvBY1e7V_normal.jpg
options(scipen = 20)
ggplot(tweets) +
geom_histogram(aes(x = followers_count))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
top5 <- tweets %>%
top_n(100, followers_count) %>%
arrange(desc(followers_count)) %>%
select(screen_name, followers_count, location, text)
ggplot(filter(tweets, !is_retweet))+
geom_histogram(aes(x = retweet_count))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
- El tweet con más rt dice lo siguiente: “Estoy sentada sola en un asiento de a dos y el colectivo está lleno, escuché “no me siento cerca de asesinas” —> pañuelo verde is the new raid"
RT1 <- tweets %>%
filter(!is_retweet) %>%
filter(retweet_count == max(retweet_count)) %>%
select(screen_name, retweet_count, followers_count, location, text)
tweets %>%
ggplot() +
geom_bar(aes(location)) +
coord_flip() +
labs(title = "Procedencia de los usuarios",
x = "cantidad",
y = "ubicación")
tweets %>%
filter(location != "", !is.na(location)) %>%
count(location) %>%
top_n(10, n) %>%
ggplot() +
geom_col(aes(x = reorder(location, n), y = n)) +
coord_flip() +
labs(title = "Procedencia de los usuarios",
x = "ubicación",
y = "cantidad")
ts_plot(tweets,"hours")
bbox <- c(min(tweets_geo$lon),
min(tweets_geo$lat),
max(tweets_geo$lon),
max(tweets_geo$lat))
mapa_fondo <- get_stamenmap(bbox, maptype = "toner-lite", zoom=11)
## Source : http://tile.stamen.com/toner-lite/11/689/1232.png
## Source : http://tile.stamen.com/toner-lite/11/690/1232.png
## Source : http://tile.stamen.com/toner-lite/11/691/1232.png
## Source : http://tile.stamen.com/toner-lite/11/692/1232.png
## Source : http://tile.stamen.com/toner-lite/11/689/1233.png
## Source : http://tile.stamen.com/toner-lite/11/690/1233.png
## Source : http://tile.stamen.com/toner-lite/11/691/1233.png
## Source : http://tile.stamen.com/toner-lite/11/692/1233.png
## Source : http://tile.stamen.com/toner-lite/11/689/1234.png
## Source : http://tile.stamen.com/toner-lite/11/690/1234.png
## Source : http://tile.stamen.com/toner-lite/11/691/1234.png
## Source : http://tile.stamen.com/toner-lite/11/692/1234.png
## Source : http://tile.stamen.com/toner-lite/11/689/1235.png
## Source : http://tile.stamen.com/toner-lite/11/690/1235.png
## Source : http://tile.stamen.com/toner-lite/11/691/1235.png
## Source : http://tile.stamen.com/toner-lite/11/692/1235.png
ggmap(mapa_fondo) +
geom_point(data = tweets_geo,
aes(x = lon, y = lat, color = followers_count,
size = retweet_count),
alpha = .5) +
scale_color_distiller(palette = "Spectral")