Skip to content

Instantly share code, notes, and snippets.

@mjhendrickson
Last active May 23, 2018 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mjhendrickson/bf85e176dbb387231d65880036d66097 to your computer and use it in GitHub Desktop.
Save mjhendrickson/bf85e176dbb387231d65880036d66097 to your computer and use it in GitHub Desktop.
Exploration of rtweet
# ----- Load libraries -----
library("rtweet")
library("devtools")
library("tidyverse")
library("gridExtra")
# ----- Connection data (removed) -----
appname <- "" # name of twitter app
key <- "" # api key
secret <- "" # api secret
token <- create_token(
app = appname,
consumer_key = key,
consumer_secret = secret)
# ----- Tweets from R4DScommunity -----
r4ds <- get_timeline(c("R4DScommunity"), n = 5000)
# Plot frequency of tweets for R4DScommunity
r4ds_plot <-
r4ds %>%
filter(created_at > "2018-04-14") %>%
ts_plot("days", trim = 1L) +
geom_point() +
theme_minimal() +
theme(
legend.title = element_blank(),
legend.position = "bottom",
plot.title = element_text(face = "bold")) +
labs(
x = NULL,
y = NULL,
title = "Frequency of @R4DScommunity Twitter Statuses",
subtitle = "Tweet counts by day since @R4DScommunity's first tweet (April 14, 2018",
caption = "\nSource: Data collected via rtweet - graphic by @mjhendrickson"
)
# ----- Tweets from mjhendrickson -----
mh <- get_timeline(c("mjhendrickson"), n = 5000)
# Plot frequency of tweets for mjhendrickson
mh_plot <-
mh %>%
filter(created_at > "2018-04-14") %>%
ts_plot("days", trim = 1L) +
geom_point() +
theme_minimal() +
theme(
legend.title = element_blank(),
legend.position = "bottom",
plot.title = element_text(face = "bold")) +
labs(
x = NULL,
y = NULL,
title = "Frequency of @mjhendrickson Twitter Statuses",
subtitle = "Tweet counts by day since April 14, 2018",
caption = "\nSource: Data collected via rtweet - graphic by @mjhendrickson"
)
# Plot together
grid.arrange(r4ds_plot, mh_plot)
@mjhendrickson
Copy link
Author

plots
mh
r4ds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment