Chris Bail
Duke University
Website: https://www.chrisbail.net
Twitter: https://www.twitter.com/chris_bail
Github: https://github.com/cbail
Navigate to:
# load rtweet
library(rtweet)
# create credentials as objects (these are FAKE CREDENTIALS)
# you need to replace them with your own.
api_key <- "aafghaioeriokjasfkljhsa"
api_secret_key <- "234897234kasdflkjashk"
# replace "my_awesome_app" with the name of YOUR app below
token <- create_token(
app = "my_awesome_app",
consumer_key = api_key,
consumer_secret = api_secret_key)
# after you run the code above, a browser window will open asking you to authorize the app.
# Once you do, you can begin making calls
covid_19_tweets<-search_tweets("coronavirus", n=4000)
names(covid_19_tweets)
head(covid_19_tweets$text)
ts_plot(covid_19_tweets, "secs") +
ggplot2::theme_minimal() +
ggplot2::theme(plot.title = ggplot2::element_text(face = "bold")) +
ggplot2::labs(
x = NULL, y = NULL,
title = "Frequency of Tweets about Covid-19 Around 1pm, May 3, 2020",
subtitle = "Tweet counts aggregated by second",
caption = "\nSource: Data collected from Twitter's REST API via rtweet"
)
covid_geo_tweets <- search_tweets("coronavirus",
"lang:en", geocode = lookup_coords("usa"),
n = 3000, type="recent", include_rts=FALSE
)
geocoded <- lat_lng(covid_geo_tweets)
par(mar = c(0, 0, 0, 0))
maps::map("world", lwd = .25)
with(geocoded, points(lng, lat, pch = 20, cex = .50, col = rgb(0, .3, .7, .75)))
trump_tweets <- get_timelines(c("realDonaldTrump
"), n = 5)
head(trump_tweets$text)
obama_twitter_profile <- lookup_users("BarackObama")
obama_twitter_profile$description
obama_twitter_profile$location
obama_twitter_profile$followers_count
obama_favorites<-get_favorites("BarackObama", n=5)
watts_followers<-get_followers("duncanjwatts")
rate_limits<-rate_limit()
head(rate_limits[50:55,1:4])
get_trends("New York")
post_tweet("This Lecture is SICSS-xy")
Note: this is a very useful function if you are building a bot
Here are a few: RgoogleMaps
, googlelanguageR
,rOpenSci,
WDI,
rOpenGov,
rtimes
Many more are available but not yet on CRAN (install from github or using devtools)
For example, visualization plotly