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.
tweets <- search_tweets(q = "Lousteau", n = 1000, include_rts = FALSE, enconding="UTF-8")
## Registered S3 method overwritten by 'openssl':
## method from
## print.bytes Rcpp
users_data(tweets) %>% head()
## # A tibble: 6 x 20
## user_id screen_name name location description url protected
## <chr> <chr> <chr> <chr> <chr> <chr> <lgl>
## 1 426763~ dana6374 "\U0~ Buenos ~ "Tecno adi~ <NA> FALSE
## 2 182196~ hduran667 El M~ "" No me mole~ <NA> FALSE
## 3 238771~ nedmerrill Igna~ Planet ~ Being. Hum~ http~ FALSE
## 4 107821~ juaniavigl~ Tuki Lima, A~ "Cada día ~ http~ FALSE
## 5 846369~ alafuente7~ Alfr~ "" Anti K y a~ <NA> FALSE
## 6 846369~ alafuente7~ Alfr~ "" Anti K y a~ <NA> FALSE
## # ... with 13 more variables: followers_count <int>, friends_count <int>,
## # listed_count <int>, statuses_count <int>, favourites_count <int>,
## # account_created_at <dttm>, verified <lgl>, profile_url <chr>,
## # profile_expanded_url <chr>, account_lang <lgl>,
## # profile_banner_url <chr>, profile_background_url <chr>,
## # profile_image_url <chr>
users_data(tweets) %>% head()
## # A tibble: 6 x 20
## user_id screen_name name location description url protected
## <chr> <chr> <chr> <chr> <chr> <chr> <lgl>
## 1 426763~ dana6374 "\U0~ Buenos ~ "Tecno adi~ <NA> FALSE
## 2 182196~ hduran667 El M~ "" No me mole~ <NA> FALSE
## 3 238771~ nedmerrill Igna~ Planet ~ Being. Hum~ http~ FALSE
## 4 107821~ juaniavigl~ Tuki Lima, A~ "Cada día ~ http~ FALSE
## 5 846369~ alafuente7~ Alfr~ "" Anti K y a~ <NA> FALSE
## 6 846369~ alafuente7~ Alfr~ "" Anti K y a~ <NA> FALSE
## # ... with 13 more variables: followers_count <int>, friends_count <int>,
## # listed_count <int>, statuses_count <int>, favourites_count <int>,
## # account_created_at <dttm>, verified <lgl>, profile_url <chr>,
## # profile_expanded_url <chr>, account_lang <lgl>,
## # profile_banner_url <chr>, profile_background_url <chr>,
## # profile_image_url <chr>
options(scipen = 20)
ggplot(tweets) +
geom_histogram(aes(x = followers_count))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
tweets %>%
top_n(40, followers_count) %>%
arrange(desc(followers_count)) %>%
select(screen_name, followers_count, location, text)
## # A tibble: 40 x 4
## screen_name followers_count location text
## <chr> <int> <chr> <chr>
## 1 eltreceofici~ 4101256 Argentina "Carla Peterson salió a ban~
## 2 eltreceofici~ 4101256 Argentina "Carla Peterson salió a ban~
## 3 clarincom 2902395 Buenos Aires~ Carla Peterson y un mensaje~
## 4 infobae 2584748 "" "El mensaje de Carla Peters~
## 5 infobae 2584748 "" "El mensaje de Carla Peters~
## 6 infobae 2584748 "" "#EleccionesArgentina Martí~
## 7 primiciasyac~ 1135557 Argentina "El mensaje de Carla Peters~
## 8 radiomitre 909694 "" El precandidato a senador p~
## 9 radiomitre 909694 "" Luego de los resultados de ~
## 10 radiomitre 909694 "" Luego de los resultados de ~
## # ... with 30 more rows
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: “Gómez Centurión y Espert sacaron entre los dos, 5% pero nos putean con todo odio, cuando igual estarían 10 puntos abajo del ladri de Fernandez. Hagan autocrítica, volanteen, re formulen, dejen de gobernar para los Peña, las feministas, Lousteau y los lobbys q nunca los votarán”
tweets %>%
filter(!is_retweet) %>%
filter(retweet_count == max(retweet_count)) %>%
select(screen_name, retweet_count, followers_count, location, text)
## # A tibble: 1 x 5
## screen_name retweet_count followers_count location text
## <chr> <int> <int> <chr> <chr>
## 1 VickyVillar~ 729 56119 Argentina Gómez Centurión y E~
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")
api_key <- "codigo_de_la_api__cortar_y_pegar_aqui"
register_google(key = api_key)
procedencia_tweets <- tweets %>%
sample_n(100) %>%
filter(!is.na(location), location != "") %>%
pull(location) %>%
geocode() %>%
group_by(lon, lat) %>%
summarise(cantidad = n())
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=CABA&key=xxx
## Warning: Geocoding "CABA" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Buenos+Aires,+Argentina&key=xxx
## Warning: Geocoding "Buenos Aires, Arg..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Republica+Argentina&key=xxx
## Warning: Geocoding "Republica Argentina" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=CIUDAD+DE+BUENOS+AIRES&key=xxx
## Warning: Geocoding "CIUDAD DE BUENOS ..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Buenos+Aires,+Argentina&key=xxx
## Warning: Geocoding "Buenos Aires, Arg..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Ciudad+Aut%C3%B3noma+de+Buenos+Aires,+Argentina&key=xxx
## Warning: Geocoding "Ciudad Autónoma d..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Almagro,+Argentina.&key=xxx
## Warning: Geocoding "Almagro, Argentina." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Palermo&key=xxx
## Warning: Geocoding "Palermo" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Paris,+France&key=xxx
## Warning: Geocoding "Paris, France" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Ciudad+Aut%C3%B3noma+de+Buenos+Aire&key=xxx
## Warning: Geocoding "Ciudad Autónoma d..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Buenos+Aires,+Argentina&key=xxx
## Warning: Geocoding "Buenos Aires, Arg..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=San+Nicolas,+Bs+As.+Argentina&key=xxx
## Warning: Geocoding "San Nicolas, Bs A..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=rosario,+provincia+de+santa+fe&key=xxx
## Warning: Geocoding "rosario, provinci..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Buenos+Aires,+Hellersland&key=xxx
## Warning: Geocoding "Buenos Aires, Hel..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Buenos+Aires&key=xxx
## Warning: Geocoding "Buenos Aires" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=argentina&key=xxx
## Warning: Geocoding "argentina" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Am%C3%A9rica+del+Sur&key=xxx
## Warning: Geocoding "América del Sur" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Argentina&key=xxx
## Warning: Geocoding "Argentina" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Ciudad+Aut%C3%B3noma+de+Buenos+Aire&key=xxx
## Warning: Geocoding "Ciudad Autónoma d..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Espa%C3%B1a&key=xxx
## Warning: Geocoding "España" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Ciudad+Aut%C3%B3noma+de+Buenos+Aire&key=xxx
## Warning: Geocoding "Ciudad Autónoma d..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Laniakea&key=xxx
## Warning: Geocoding "Laniakea" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Cabrero+y+Guidi.&key=xxx
## Warning: Geocoding "Cabrero y Guidi." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Argentina&key=xxx
## Warning: Geocoding "Argentina" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Ciudad+Aut%C3%B3noma+de+Buenos+Aire&key=xxx
## Warning: Geocoding "Ciudad Autónoma d..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=C%C3%B3rdoba,+Rep%C3%BAblica+Argentina&key=xxx
## Warning: Geocoding "Córdoba, Repúblic..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Moscu&key=xxx
## Warning: Geocoding "Moscu" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Bs.+As.&key=xxx
## Warning: Geocoding "Bs. As." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=C%C3%B3rdoba,+Argentina&key=xxx
## Warning: Geocoding "Córdoba, Argentina" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=9/3/14+Dia+Inolvidable&key=xxx
## Warning: Geocoding "9/3/14 Dia Inolvi..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Buenos+Aires,+Argentina&key=xxx
## Warning: Geocoding "Buenos Aires, Arg..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Buenos+Aires,+Argentina&key=xxx
## Warning: Geocoding "Buenos Aires, Arg..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Bs+As,+pcia&key=xxx
## Warning: Geocoding "Bs As, pcia" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=NEPTUNO&key=xxx
## Warning: Geocoding "NEPTUNO" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=San+Fernando+del+Valle+de+Cata&key=xxx
## Warning: Geocoding "San Fernando del ..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Rosario&key=xxx
## Warning: Geocoding "Rosario" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=San+Luis+-+Argentina&key=xxx
## Warning: Geocoding " San Luis - Argen..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Laniakea&key=xxx
## Warning: Geocoding "Laniakea" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Buenos+Aires,+Argentina&key=xxx
## Warning: Geocoding "Buenos Aires, Arg..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Un+lugar+llamado+Tucum%C3%A1n&key=xxx
## Warning: Geocoding "Un lugar llamado ..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Estadio+Santiago+Bernab%C3%A9u&key=xxx
## Warning: Geocoding "Estadio Santiago ..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Porte%C3%B1isima&key=xxx
## Warning: Geocoding "Porteñisima " failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Floridablanca,+Colombia&key=xxx
## Warning: Geocoding "Floridablanca, Co..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Santa+Rosa,+Argentina&key=xxx
## Warning: Geocoding "Santa Rosa, Argen..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Buenos+Aires,+Argentina&key=xxx
## Warning: Geocoding "Buenos Aires, Arg..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Salta,+Argentina&key=xxx
## Warning: Geocoding "Salta, Argentina" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Tucum%C3%A1n+City&key=xxx
## Warning: Geocoding "Tucumán City" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Ciudad+Aut%C3%B3noma+de+Buenos+Aire&key=xxx
## Warning: Geocoding "Ciudad Autónoma d..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Argentina&key=xxx
## Warning: Geocoding "Argentina" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Buenos+Aires&key=xxx
## Warning: Geocoding "Buenos Aires" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Buenos+Aires,+Argentina&key=xxx
## Warning: Geocoding "Buenos Aires, Arg..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Ciudad+Aut%C3%B3noma+de+Buenos+Aire&key=xxx
## Warning: Geocoding "Ciudad Autónoma d..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Paternal&key=xxx
## Warning: Geocoding "Paternal" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Formosa,+Argentina&key=xxx
## Warning: Geocoding "Formosa, Argentina" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Tucum%C3%A1n,+Argentina&key=xxx
## Warning: Geocoding "Tucumán, Argentina" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Konoha&key=xxx
## Warning: Geocoding "Konoha" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=San+Luis,+Argentina&key=xxx
## Warning: Geocoding "San Luis, Argentina" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Buenos+Aires,+Argentina&key=xxx
## Warning: Geocoding "Buenos Aires, Arg..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Rosario+(SFe)+Argentina&key=xxx
## Warning: Geocoding "Rosario (SFe) Arg..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Tucum%C3%A1n,+Argentina&key=xxx
## Warning: Geocoding "Tucumán, Argentina" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Buenos+Aires,+Argentina&key=xxx
## Warning: Geocoding "Buenos Aires, Arg..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=San+Juan,+Argentina&key=xxx
## Warning: Geocoding "San Juan, Argentina" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Buenos+Aires,+Argentina&key=xxx
## Warning: Geocoding "Buenos Aires, Arg..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=La+Matanza,+Argentina&key=xxx
## Warning: Geocoding "La Matanza, Argen..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Concordia,+Argentina&key=xxx
## Warning: Geocoding "Concordia, Argentina" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Ciudad+Aut%C3%B3noma+de+Buenos+Aire&key=xxx
## Warning: Geocoding "Ciudad Autónoma d..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Buenos+Aires&key=xxx
## Warning: Geocoding "Buenos Aires" failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Estadio+Santiago+Bernab%C3%A9u&key=xxx
## Warning: Geocoding "Estadio Santiago ..." failed with error:
## The provided API key is invalid.
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Buenos+Aires&key=xxx
## Warning: Geocoding "Buenos Aires" failed with error:
## The provided API key is invalid.
ggplot(procedencia_tweets) +
borders("world") +
geom_point(aes(x = lon, y = lat, size = cantidad), alpha = .4, color = "red") +
labs(title = "Procedencia de los tweets capturados")
## Warning: Removed 1 rows containing missing values (geom_point).
tweets_guga <- search_tweets(q = "Lousteau",
geocode = "-34.603722,-58.381592,20mi",
include_rts = FALSE,
n = 20000,
retryonratelimit = TRUE)