Twitter

rmba <- st_read("/Users/nadia/Downloads/vazquez-brust-regin-metropolitana-de-buenos-aires/RMBA.shp")
## Reading layer `RMBA' from data source `/Users/nadia/Downloads/vazquez-brust-regin-metropolitana-de-buenos-aires/RMBA.shp' using driver `ESRI Shapefile'
## Simple feature collection with 15122 features and 7 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: -59.37685 ymin: -35.42203 xmax: -57.70947 ymax: -33.80567
## epsg (SRID):    4326
## proj4string:    +proj=longlat +datum=WGS84 +no_defs
tw_rmba <- read.csv("/Users/nadia/Downloads/tweets_rmba.csv",
                         header = TRUE, 
                        sep = ",",
                        stringsAsFactors = FALSE)
tw_rmba01 <- sample_frac(tw_rmba, 0.1) 
tw_rmba01 %>% 
  select(user_name, user_followers, user_location, text) %>%
  group_by(user_name) %>% 
  summarise(user_followers = last(user_followers),
            text = last(text), 
            user_location = last(user_location)) %>% 
  distinct() %>% 
    top_n(5, user_followers) %>% 
    arrange(desc(user_followers)) 
## # A tibble: 5 x 4
##   user_name   user_followers text                          user_location   
##   <chr>                <int> <chr>                         <chr>           
## 1 andykusnet…        2431152 Nadie gana ningún premio sol… Buenos Aires, A…
## 2 pampitaofi…        2096032 @trosman_oficial @jessicatro… Buenos Aires    
## 3 Facundo_Ar…        1738061 #Mendoza!! 13 y 14 de Abril,… Tigre, Argentina
## 4 RicardoMor…        1710418 Anoche con @alessarampolla e… ""              
## 5 mmatiasale         1593917 Fiesta de fin de año de UPCN… ""
tw_rmba01 <- tw_rmba01 %>%
mutate(created_at = str_remove(created, "\\+00"))

ts_plot(tw_rmba01, by = "hours")

tw_rmba01 %>% 
  select(user_name, user_followers, user_location) %>%
  group_by(user_name) %>% 
  summarise(user_followers = last(user_followers),
            user_location = last(user_location)) %>% 
  distinct() %>% 
    top_n(5, user_followers) %>% 
    arrange(desc(user_followers)) 
## # A tibble: 5 x 3
##   user_name      user_followers user_location          
##   <chr>                   <int> <chr>                  
## 1 andykusnetzoff        2431152 Buenos Aires, Argentina
## 2 pampitaoficial        2096032 Buenos Aires           
## 3 Facundo_Arana         1738061 Tigre, Argentina       
## 4 RicardoMoran          1710418 ""                     
## 5 mmatiasale            1593917 ""
options(scipen = 20)
ggplot(tw_rmba01) +
    geom_histogram(aes(x = user_followers))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

api_key <- "AIzaSyDOCg2uMWsISkQJOpYsUEgQKAEmKZVoQkk"
register_google(key = api_key)
tw_rmba01 %>%
    filter(user_location != "", !is.na(user_location)) %>% 
    count(user_location) %>% 
    top_n(10, n) %>% 
    ggplot() +
      geom_col(aes(x = reorder(user_location, n), y = n)) + 
      coord_flip() +
      labs(title = "Procedencia de los usuarios",
           x = "ubicación",
           y = "cantidad")

En estos ultimos dos chunks nos da error, que la columna X no existe, y si pongo primero Y y luego X me dice que la columna Y no existe, no encuentro que estamos haciendo mal.

Lo pongo para que lo veas:

procedencia_tweets <- tw_rmba01 %>% sample_n(100) %>% filter(!is.na(user_location), user_location != "") %>% pull(user_location) %>% geocode() %>% group_by(x, y) %>% summarise(cantidad = n())

Error: Column “X” is unknown

ggplot(procedencia_tweets) + borders(“world”) + geom_point(aes(x = x, y = y, size = cantidad), alpha = .4, color = “orange”) + labs(title = “Procedencia de los tweets capturados”) ```

Error: object “X” not found