Last active
January 7, 2017 04:52
-
-
Save mkearney/724c9f536fb3d40513d6dbbcdc52853d to your computer and use it in GitHub Desktop.
Example of ts_plot() and stream_tweets() from rtweet pkg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rtweet) | |
## use stream_tweets() to capture an hour of tweets | |
"wikileaks,assange,hacking,russia,putin" %>% | |
stream_tweets( | |
parse = FALSE, | |
timeout = (60 * 60), | |
file_name = "wikileaks.json") | |
## read and parse data | |
rt <- parse_stream("wikileaks.json") | |
## plot to png | |
png("ts_plot-ex-hacking.png", 8, 5, "in", res = 127.5) | |
par(family = "Avenir") | |
rt %>% | |
subset(!is.na(created_at)) %>% | |
ts_plot( | |
"21 secs", filter = c( | |
"trump|elect|peotus", | |
"obama", | |
"assange|wikileaks", | |
"russia|putin", | |
"cia|fbi|intelligence" | |
), | |
key = c("Trump", "Obama", "Wikileaks", | |
"Russia", "CIA/FBI"), | |
main = "rtweet: Collecting Twitter data", | |
box = FALSE, adj = 0, xtime = "%T", | |
theme = "spacegray") | |
## subtitle will be built-in to ts_plot soon to simplify this | |
text(.1925, 1.125, cex = .75, "", | |
col = "white", xpd = FALSE) | |
text(.1925, 1.125, cex = .75, | |
"Using stream_tweets() to capture tweets about hacking", | |
col = "white", xpd = TRUE) | |
dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment