Created
February 5, 2022 21:21
-
-
Save ikashnitsky/fc3996a879a2957c75c052df0b0cfcea to your computer and use it in GitHub Desktop.
Young Demographers twitter – https://twitter.com/ikashnitsky/status/1490071934687666191
This file contains hidden or 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
#=============================================================================== | |
# 2022-02-05 -- twitter | |
# Young Demographers in twitter | |
# Ilya Kashnitsky, [email protected], @ikashnitsky | |
#=============================================================================== | |
library(tidyverse) | |
library(magrittr) | |
library(hrbrthemes) | |
library(rtweet) | |
library(ggdark) | |
library(ggrepel) | |
yd <- search_tweets( | |
"#YoungDemographers", n = 18000, include_rts = FALSE | |
) | |
# N tweets by user | |
yd %>% | |
group_by(screen_name) %>% | |
summarise( | |
n = n() | |
) %>% | |
arrange(n %>% desc) %>% | |
mutate(screen_name = screen_name %>% as_factor()) %>% | |
ggplot(aes(n, screen_name %>% fct_rev))+ | |
geom_segment(aes(x = 0, xend = n, yend = screen_name %>% fct_rev))+ | |
geom_point()+ | |
scale_x_continuous(position = "top")+ | |
dark_theme_minimal(base_family = font_rc)+ | |
theme( | |
axis.text.y = element_text(face = 2, size = 10, color = "#ffffff"), | |
plot.title = element_text(face = 2, family = "Roboto Slab") | |
)+ | |
labs( | |
y = NULL, | |
x = "Number of tweets", | |
caption = "Data exported on 2022-02-05 | @ikashnitsky", | |
title = "Accounts tweeting about #YoungDemographers" | |
) | |
ggsave("~/Downloads/n-tweets.png", | |
width = 6.4, height = 3.6, type = "cairo") | |
# likes vs followers | |
set.seed(126) | |
yd %>% | |
group_by(screen_name) %>% | |
summarise( | |
avg_likes = favorite_count %>% mean, | |
followers_count = followers_count[1], | |
n = n() | |
) %>% | |
ggplot(aes(followers_count, avg_likes, weight = n))+ | |
geom_hline(aes(yintercept = avg_likes %>% median), color = "#ffcdd277")+ | |
geom_vline(aes(xintercept = followers_count %>% median), color = "#ffcdd277")+ | |
geom_text_repel(aes(label = screen_name), color = "#ffffff", size = 3, family = font_rc)+ | |
geom_point(aes(size = n, alpha = 1/(n^.2), color = avg_likes/followers_count))+ | |
scale_y_comma(trans = "log", breaks = 10^(0:3))+ | |
scale_x_comma(trans = "log", breaks = 10^(0:5), position = "top")+ | |
scale_size_area(guide = NULL)+ | |
scale_color_viridis_c(option = "H", guide = guide_colorbar(barwidth = 15, direction = "horizontal", title.position = "top"))+ | |
scale_alpha_identity()+ | |
coord_cartesian()+ | |
dark_theme_minimal(base_family = font_rc)+ | |
theme( | |
plot.title = element_text(face = 2, family = "Roboto Slab"), | |
legend.position = "bottom" | |
)+ | |
labs( | |
x = "Followers count", | |
y = "Average likes count", | |
color = "Ratio of avg likes to followers", | |
caption = "Data exported on 2022-02-05, 22 accounts, size mapped to # of tweets | @ikashnitsky", | |
title = 'Accounts tweeting about "#YoungDemographers"' | |
) | |
ggsave("~/Downloads/likes-followers.png", | |
width = 6.4, height = 3.6, type = "cairo") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment