Skip to content

Instantly share code, notes, and snippets.

@genomewalker
Last active June 28, 2024 09:34
Show Gist options
  • Save genomewalker/138cb789abe1411f03b0f529154de684 to your computer and use it in GitHub Desktop.
Save genomewalker/138cb789abe1411f03b0f529154de684 to your computer and use it in GitHub Desktop.
Code for making publication lists
library(scholar) # to get publications and impact factors
library(stringr) # to modify text
library(cowplot) # for plotting
library(ggplot2)
library(ggrepel)
library(lemon)
library(dplyr)
# Set variables
Scholar_ID <- "wA7Hrk8AAAAJ"
# This is your author scholar Id, it'll be found in the address of your scholar profile after user=and before &, https://scholar.google.com/citations?user=Sc3CfZsAAAAJ&hl=en
Author_fullname <- c("Antonio Fernandez-Guerra", "Antoni Fernandez-Guerra") # full name as it appears in articles in pubmed
Author_lastname <- c("Fernandez-Guerra", "Fernández-Guerra", "Fernàndez-Guerra") # last name and alternative spellings
# Get publication record from scholar
df <- get_publications(Scholar_ID) %>%
as_tibble() %>%
rename(
title = 1, authors = 2, journal = 3, number = 4, total_citations = 5,
publication_date = 6, cid = 7, pubid = 8
)
################## ALTERNATIVE ###########
# if for some reason getting publications with scholar is not working use these commands for gcite
# install.packages("gcite")
# library(gcite)
# SC<-gcite(user=Scholar_ID,plot_wordcloud = FALSE)
# df<-SC$paper_df
##########################################
df <- df %>%
filter(!is.na(journal), !is.na(publication_date)) %>%
mutate(year = publication_date)
# remove publications from blacklist
blacklist <- c("1Aeql8wG3wEC", "SPgmg5JLkoEC", "qbqt7gslDFUC", "DPO9WFcz7UcC", "WF5omc3nYNoC", "WM2K3OHRCGMC", "g30IDTdgJMgC", "w0odbtu79TwC", "dhpJJ7xvgBgC", "e9bUPLv0EjcC", "PklR0melJeUC", "KsTgnNRry18C", "yKzB5RS27GgC", "QtA78RmWg5MC", "o-PowTg_VKEC", "1Aeql8wG3wEC", "uWy0R8PweswC", "vofGIMt6cyEC")
View(df %>% filter(!(pubid %in% blacklist)) %>% select(title, total_citations, pubid))
View(df %>% select(title, total_citations, pubid))
# Get impact factor
IF <- get_impactfactor(df$journal) # get impact factor for journals, some might not be accurate and may require to be changed manually
df <- cbind(df, IF) # add impact factors to data frame
# IMPORTANT #
# the get_impactfactor function is prone to error, so verify and correct, some journal names are not found or get replaced by others
# Highlight first author paper
df <- df %>%
mutate(first = ifelse(grepl(paste(Author_lastname, collapse = "|"), str_split_fixed(authors, ",", 2)[, 1]), 1, 0))
# This does not identify equal contribution first authors, those would have to be entered manually
df <- df %>%
mutate(first = ifelse(journal == "Nature biotechnology", 1, first)) %>%
arrange(year)
# Highlight custom papers
Highlight <- c("Nature biotechnology") # Create a vector for those articles you'd like to show the name or logo of the journal
df <- df %>%
mutate(labels = ifelse(journal %in% Highlight, as.character(journal), NA))
# Optional: limit to publications after a given year, I have only tested the code using ~10 years
df <- df %>%
filter(year >= 2005)
# Plot
p1v1 <- ggplot(df, aes(y = ImpactFactor, x = year)) +
geom_point(aes(fill = ImpactFactor, stroke = first), size = 4, shape = 21, na.rm = TRUE) + # points filled according to impact factor, with border according to first author
geom_text_repel(aes(label = labels), xlim = c(max(df$year) + 2, Inf), ylim = c(-Inf, Inf), min.segment.length = 0, na.rm = TRUE) + # add labels starting 2 years after the x limit
theme_cowplot() +
coord_cartesian(clip = "off") +
coord_capped_cart(bottom = "both") +
scale_fill_gradient2(low = "grey70", mid = "khaki3", high = "deepskyblue3", guide = FALSE) + # create color scale
scale_x_continuous(breaks = c(min(df$year), max(df$year)), limits = c(min(df$year), max(df$year) + 15)) + # modify x axis to expand to the right, but only label years with data
coord_capped_cart(bottom = "both") + # limit the line on the x axis to the limits
continuous_scale("stroke", "stroke", palette = function(x) {
scales::rescale(x, c(0, 1.5))
}, breaks = c(1), labels = c("First author"), name = NULL) + # Modify scale for stroke size
ggtitle("Journal Impact Factor") +
# modify axes to clean up the plot
xlab("Year of publication") +
theme(
axis.title.x = element_text(angle = 0, color = "black", hjust = 0.05, size = 11), axis.text.x = element_text(size = 9, color = "grey30"),
axis.line.y = element_blank(), panel.grid.major.y = element_line(color = "grey", linetype = 3), axis.title.y.left = element_blank(), axis.text.y = element_text(size = 9, color = "grey30"), # y axis
plot.title = element_text(color = "grey40", face = "bold", size = 12), # title
legend.position = c(0.6, 0), legend.text = element_text(size = 9, color = "grey30") # legend
)
p1v1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment