Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
141 lines (109 sloc) 3.7 KB
title date tags slug output
My #Best9of2018 tweets
2018-12-28
magick
Twitter
best9of2018
md_document
variant preserve_yaml
markdown_github
true

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:

  • I created rows then columns instead of the other way round, because that’s what Instagram does. I did not pay attention to this last year but Andrew Caines told me this in a comment.

  • I did not save the intermediary images to disk. I’ve upped my magick game!

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")

best 9 of 2018

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!