Site icon R-bloggers

My #Best9of2018 tweets

[This article was first published on Posts on Maëlle's R blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

As 2018 nears its end, it’s time for me to look back on my R/Twitter year with the same simple method as last year: let me identify and webshoot my 9 best tweets of 2018!

Downloading and opening my Twitter data

Like in 2017 I tweeted too much and therefore was unable to rely on rtweet::get_timeline() (or rtweet::get_my_timeline()) to download my tweets so I exported data via the Tweets tab of https://analytics.twitter.com/. Last year, I downloaded one file per quarter but somehow had to download one per month this time. It was monotonous but not horrible.

library("magrittr")

dir("data", full.names = TRUE) %>%
  purrr::map_df(readr::read_csv) %>%
  unique() -> my_tweets

4196 tweets!

Getting the top 9 tweets

Similarly to my 2017 post, I chose the number of likes as criterion to define my best tweets.

my_tweets <- dplyr::arrange(my_tweets, - likes)
my_tweets <- janitor::clean_names(my_tweets)

knitr::kable(my_tweets[1:9, "likes"])
likes
162
151
128
112
95
94
91
86
75
best9 <- my_tweets$tweet_permalink[1:9]

The table above shows that my best tweets were not extremely popular.

Webshooting and combining the tweets

My 2017 blog post inspired Bob Rudis to contribute a tweet_shot() function to rtweet, relying on the webshot package, so that’s what I used.

shot <- function(permalink){
  rtweet::tweet_shot(permalink) %>%
    magick::image_crop(magick::geometry_area(width = 517,
                                             height = 517,
                       y_off = 88)) %>%
    magick::image_border("salmon", "20x20")
}

images <- purrr::map(as.character(best9),
                     shot)

I improved the collage code with two tweaks:

make_row <- function(i, images){
  images[((i-1)*3+1):((i-1)*3+3)] %>%
    magick::image_join() %>%
    magick::image_append()
}

purrr::map(1:3, make_row,
           images = images) %>%
  magick::image_join() %>%
  magick::image_append(stack = TRUE) %>%
  magick::image_border("salmon", "20x20")

Worth noting from my R year are, according to these tweets,

What about your R year, on Twitter and elsewhere? Have a good last days of 2018, and a happy 2019!

To leave a comment for the author, please follow the link and comment on their blog: Posts on Maëlle's R blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.