Skip to content

Instantly share code, notes, and snippets.

@micahwoods
Last active August 29, 2015 14:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save micahwoods/69b9df6a3f48aa62df5a to your computer and use it in GitHub Desktop.
downloads user timeline and plots before and after interactions from a cutoff date and time
# load packages
library("twitteR")
library("dplyr")
library("lubridate")
api_key <- "your key"
api_secret <- "your secret"
access_token <- "your token"
access_token_secret <- "your token secret"
setup_twitter_oauth(api_key, api_secret, access_token, access_token_secret)
# for @TurfDiseases account
tweets <- userTimeline("TurfDiseases", n = 1000, includeRts = TRUE)
tweetsDF <- twListToDF(tweets)
original <- filter(tweetsDF, isRetweet == FALSE)
# cutoff tweets from specified date and time
cutoff <- ymd_hms("2015-01-16 12:00:00")
original$created <- ymd_hms(original$created)
new <- filter(original, created > cutoff)
old <- filter(original, created < cutoff)
new$interaction <- new$favoriteCount + new$retweetCount
old$interaction <- old$favoriteCount + old$retweetCount
mean(old$interaction)
mean(new$interaction)
median(old$interaction)
median(new$interaction)
plot(density(old$interaction), col = "blue",
xlab = "interaction per tweet (favorite + retweet)",
main = "@TurfDiseases tweets before & after 2015-01-16 12:00")
lines(density(new$interaction), col = "red")
text(x = 5, y = .4, adj = 0,
labels = "before 2015-01-16 12:00\nn = 699\nmean = 1.49\nmedian = 0",
col = "blue")
text(x = 10, y = .2, adj = 0,
labels = "after 2015-01-16 12:00\nn = 39\nmean = 2.62\nmedian = 2",
col = "red")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment