Skip to content

Instantly share code, notes, and snippets.

@ikashnitsky
Last active July 19, 2022 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikashnitsky/07f4f4e3b247dfeeeaf25af9b12fd78f to your computer and use it in GitHub Desktop.
Save ikashnitsky/07f4f4e3b247dfeeeaf25af9b12fd78f to your computer and use it in GitHub Desktop.
Draw automatically citation water bubbles plot for the journal of your choice, you need to input Scopus dataframe – https://twitter.com/ikashnitsky/status/1529195306981662720
#===============================================================================
# 2022-05-23 -- twitter
# citation water bubbles plot
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com, @ikashnitsky
#===============================================================================
# This script introduces a function that draws a citation water bubbles plot
# https://twitter.com/ikashnitsky/status/1528834190908739587
# The only necessary input is a dataframe with journal's papers exported from
# Scopus. Note: that Scopus only allows to download 2000 entries at once. If
# a journal of your choice has published more than 2000 papers, you can either
# export bibliometric data several times, or just use the top-2000 ever cited.
# The csv exported from Scopus is read in R by simple read_csv()
library(tidyverse)
library(magrittr)
library(hrbrthemes)
# the code below assumes that you have installed fonts
# Roboto Condensed and Roboto Slab
library(ggrepel)
library(ggforce)
library(prismatic)
# the function
journal_citations_bubbles <- function(
# the only parameter that you *have* to provide
# an export csv from Scopus with journal's all papers
# read in R by simple read_csv()
scopus_df,
# this is a random choice of one of the material 700 colors
# https://material.io/resources/color
bubble_color = c("#D22E2EFF", "#C1185AFF", "#7A1FA1FF", "#512CA7FF", "#303F9FFF", "#1976D2FF", "#0187D1FF", "#0097A6FF", "#00796BFF", "#388D3BFF", "#679F38FF", "#AEB32BFF", "#FABF2CFF", "#FF9F00FF", "#F47B00FF", "#E54A19FF", "#5D3F37FF", "#455964FF") %>% sample(1),
line_color = bubble_color %>% clr_darken(shift = .3),
# max size of the bubbles
max_size = 6,
# should Y-axis by log10? (default to FALSE)
log10 = FALSE,
zoom = TRUE,
zoom_limits = NULL
) {
scopus_df <- scopus_df %>% janitor::clean_names()
n_papers <- scopus_df %>% nrow
h_ind <- scopus_df %>%
arrange(cited_by %>% desc) %>%
mutate(rank = row_number()) %>%
summarise(h_ind = which(rank <= cited_by) %>% max) %>%
pull(h_ind)
journal_title <- scopus_df %>% pull(source_title) %>% first()
p <- scopus_df %>%
ggplot(aes(year, cited_by))+
geom_hline(yintercept = 0, size = .75, color = "#3a3a3a")+
geom_jitter(
aes(size = cited_by),
width = .2,
alpha = .25, color = bubble_color
)+
scale_size_area(max_size = max_size)+
geom_point(
data = . %>%
group_by(year) %>%
summarise(cited_by = cited_by %>% median(na.rm = T)),
shape = 45, size = 10, color = line_color
)+
geom_smooth(
data = . %>%
group_by(year) %>%
summarise(cited_by = cited_by %>% median(na.rm = T)),
size = 1, color = line_color %>% clr_alpha(.5),
se = F, span = .85
)+
geom_text_repel(
data = . %>%
filter(cited_by >= h_ind*1.1) %>%
mutate(
label = authors %>% str_extract("^([^,])+")
),
aes(label = label),
nudge_y = 1, hjust = 1, size = 3, family = font_rc,
segment.color = "#7a7a7a77",
ylim = c(h_ind*1.2, Inf)
)+
theme_gray(base_family = font_rc, base_size = 16)+
theme(
plot.title = element_text("Roboto Slab", face = 2, size = 24),
legend.position = "none"
)+
labs(
x = NULL,
y = "Times cited",
color = NULL,
caption = "@ikashnitsky",
title = paste0(journal_title, ": ", n_papers, " papers, h-index ", h_ind)
)+
coord_cartesian(expand = T)
if(zoom == TRUE & is.null(zoom_limits)){
return(p +
facet_zoom(ylim = c(0, h_ind), zoom.size = 1))
}
if(zoom == TRUE & !is.null(zoom_limits)){
return(p +
facet_zoom(ylim = zoom_limits, zoom.size = 1))
} else {
return(p)
}
}
# # save the output with reasonable dimensions
# ggsave(
# "~/Downloads/water-bubbles.png",
# width = 12.8, height = 7.2,
# type = "cairo-png", bg = "#ffffff"
# )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment