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:
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")
Worth noting from my R year are, according to these tweets,
my re-designing my website;
the slides of my R-Ladies Strasbourg talk about how to be a resilient R user;
my starting work at rOpenSci and Locke Data (yay!);
my blog post about rainbowing a set of pictures;
another blog post featuring
magick
, about combining hexes but I’d recommend reading this post by Mitchell O’Hara Wild instead;my blog post about where to get R help that might be the personal blog post I’m the proudest of.
What about your R year, on Twitter and elsewhere? Have a good last days of 2018, and a happy 2019!
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.