Skip to content

Instantly share code, notes, and snippets.

@wesslen
Created July 20, 2018 16:15
Show Gist options
  • Select an option

  • Save wesslen/72716aa74b5f558215de0c61e64de6fa to your computer and use it in GitHub Desktop.

Select an option

Save wesslen/72716aa74b5f558215de0c61e64de6fa to your computer and use it in GitHub Desktop.
combine multiple rtweet streams
library(rtweet)
library(dplyr)
files <- list.files()
files <- files[grep(".json", files)]
getPoints <- function(file){
parse_stream(file) %>%
lat_lng("bbox_coords") %>% # keep bounding box coords
filter(is_retweet == FALSE & !is.na(lat)) %>% # keep posts and point lat/longs
select(status_id, created_at, screen_name, text, is_retweet, lat, lng) # whatever columns to select
}
df <- purrr::map_df(files, getPoints)
## plot state boundaries
par(mar = c(0, 0, 0, 0))
maps::map("state", lwd = .25)
## plot lat and lng points onto state map
with(df, points(lng, lat, pch = 20, cex = .75, col = rgb(0, .3, .7, .75)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment