Last active
November 7, 2017 18:27
-
-
Save johnmackintosh/9bfe322ccb270d371e249855a88577c2 to your computer and use it in GitHub Desktop.
trying out rtweet package R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rtweet) | |
library(tidyverse) | |
library(dplyr) | |
library(hrbrthemes) | |
library(extrafont) | |
library(viridis) | |
## create token named "twitter_token" | |
twitter_token <- create_token( | |
app = appname, | |
consumer_key = key, | |
consumer_secret = secret) | |
event <- search_tweets("#nhshsepsis") | |
event | |
# who tweeted the most? | |
data <- event %>% select (screen_name,status_id,text,created_at,retweet_count, | |
favorite_count,is_retweet,source,mentions_screen_name,hashtags) | |
most_tweets <- data %>% | |
group_by(screen_name) %>% | |
tally(sort=TRUE) %>% | |
arrange(n) %>% | |
ggplot(aes(reorder(screen_name, n),n))+ | |
geom_col()+ | |
ggtitle("Most Tweets - NHS Highland Sepsis Event\n 6th Nov 2017")+ | |
xlab(NULL) + ylab(NULL)+ | |
coord_flip()+ | |
theme_ipsum() | |
most_tweets | |
ggsave("2017-11-06-most-tweets.png") | |
# whose tweets were most favourited | |
most_favs <- data %>% | |
group_by(favorite_count,screen_name) %>% | |
tally(sort=TRUE) %>% | |
arrange(favorite_count) %>% | |
ggplot(aes(reorder(screen_name, favorite_count),favorite_count))+ | |
geom_bar(stat="identity")+ | |
ggtitle("Most Favourited - NHS Highland Sepsis Event\n 6th Nov 2017")+ | |
xlab(NULL) + ylab(NULL)+ | |
coord_flip()+ | |
theme_ipsum()+ | |
scale_fill_viridis(discrete = TRUE) | |
most_favs | |
ggsave("2017-11-06-most-favs.png") | |
#Apple or Android? Or something else? | |
devices <- data %>% | |
group_by(source) %>% | |
tally(sort=TRUE) %>% | |
arrange(n) %>% | |
ggplot(aes(reorder(source, n),n))+ | |
geom_col()+ | |
ggtitle("Most Popular Devices in use -\ NHSH Tweeters")+ | |
xlab(NULL) + ylab(NULL)+ | |
coord_flip()+ | |
theme_ipsum() | |
devices | |
ggsave("2017-11-06-devices.png") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment