Skip to content

Instantly share code, notes, and snippets.

@mkearney
Created January 7, 2017 04:27
Show Gist options
  • Save mkearney/e62e8e9a34b6983427af9449a60093cc to your computer and use it in GitHub Desktop.
Save mkearney/e62e8e9a34b6983427af9449a60093cc to your computer and use it in GitHub Desktop.
Example of ts_plot() from rtweet pkg
## download dev version of rtweet (from github)
install.packages("devtools")
devtools::install_github("mkearney/rtweet")
library(rtweet)
## search for 15k tweets using keywords
## (my goal was to explore current political opinions
## so it made sense to me to exclude retweets and
## use personal/opinion keywords, e.g., "i think")
rt <- search_tweets(
"I think trump", n = 15000, include_rts = FALSE)
## use rtweet's ts_plot() function to aggregate and plot
## multiple time series (filtered via regular expressions
## and tweet text) over 2 hour increments.
## the "spacegray" theme is currently my fav but the
## "nerd" theme is a close second.
rt %>%
ts_plot("2 hours",
cols = c("#ff6666", "#6688ff", "#ffffff"),
filter = c("wikileaks|assange",
"cia|fbi|intelligence",
"russia|putin"),
theme = "spacegray", lwd = 2.25,
xtime = "%b %e")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment