Skip to content

Instantly share code, notes, and snippets.

@gorkang
Last active October 6, 2020 08:03
Show Gist options
  • Save gorkang/bf6bc9ca08cad340cea1df3d815c5eb7 to your computer and use it in GitHub Desktop.
Save gorkang/bf6bc9ca08cad340cea1df3d815c5eb7 to your computer and use it in GitHub Desktop.
Trump tweets
# Using {rtweet} (https://github.com/ropensci/rtweet) to check how much Trump tweeted in the last few days
# Libraries
library(rtweet)
library(tidyverse)
# Get Twitter token
file_name <- file.path(".rtweet_token5.rds")
twitter_token = readRDS(file = file_name)
# Read tweets
DF = get_timeline("@realDonaldTrump", n = 700, token = twitter_token)
# Prepare data
DF_plot = DF %>%
mutate(Date = as.Date(created_at))
# Plot tweets
plot1 =
DF_plot %>%
ggplot(aes(Date)) +
geom_histogram(bins = 18, binwidth = 1) +
theme_minimal(base_size = 14) +
scale_x_date(breaks = scales::breaks_pretty(18)) +
scale_y_continuous(breaks = scales::breaks_pretty(20), limits = c(0, 97)) +
labs(subtitle = "Number of tweets by @realDonaldTrump in the last couple weeks") +
theme(legend.position = "none")
plot1
ggsave("trump_tweets.png", plot1, dpi = 150, width = 15, height = 12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment