Skip to content

Instantly share code, notes, and snippets.

@SimonCoulombe
Created October 31, 2018 14:29
Show Gist options
  • Save SimonCoulombe/42f37e3622429a25053cb75e30542429 to your computer and use it in GitHub Desktop.
Save SimonCoulombe/42f37e3622429a25053cb75e30542429 to your computer and use it in GitHub Desktop.
## install rtweet from CRAN
install.packages("rtweet")
## load rtweet package
library(rtweet)
create_token(
app = "my_twitter_research_app",
consumer_key = Sys.getenv("twitter_consumer_key"),
consumer_secret = Sys.getenv("twitter_consumer_secret"),
access_token = Sys.getenv("twitter_access_token"),
access_secret = Sys.getenv("twitter_access_secret"))
rt <- search_tweets(
"#rstats", n = 18000, include_rts = FALSE
)
## plot time series of tweets
ts_plot(rt, "3 hours") +
ggplot2::theme_minimal() +
ggplot2::theme(plot.title = ggplot2::element_text(face = "bold")) +
ggplot2::labs(
x = NULL, y = NULL,
title = "Frequency of #rstats Twitter statuses from past 9 days",
subtitle = "Twitter status (tweet) counts aggregated using three-hour intervals",
caption = "\nSource: Data collected from Twitter's REST API via rtweet"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment