Created
May 11, 2022 19:32
-
-
Save mcfrank/cc596d4c9f906e24bdc8efb8a4ac1e63 to your computer and use it in GitHub Desktop.
example use of Scopus API for a citation network
This file contains 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
library(rscopus) | |
library(tidyverse) | |
library(igraph) | |
library(GGally) | |
faculty <- read_csv("faculty.csv") | |
faculty$au_id <- NA | |
for (i in 1:nrow(faculty)) { | |
print(i) | |
Sys.sleep(.5) # to solve timeout problem | |
au_id <- get_author_info(last_name = faculty$last[i], | |
first_name = faculty$first[i], | |
affil_id = faculty$affiliation[i])$au_id[1] | |
faculty$au_id[i] = ifelse(!is.null(au_id), au_id, NA) | |
} | |
# Get all articles by each faculty member. | |
articles <- faculty |> | |
mutate(idx = 1:n()) %>% | |
split(.$idx) |> | |
map_df(function(f) { | |
print(f$idx) | |
Sys.sleep(.5) | |
author_df(au_id = f$au_id, | |
affil_id = f$affiliation, | |
verbose=FALSE) |> | |
mutate(faculty = f$last) | |
}) | |
articles <- as_tibble(articles) | |
multi_author <- articles |> | |
group_by(`dc:identifier`) |> | |
summarise(n_authors = length(unique(faculty))) |> | |
filter(n_authors > 1) | |
edgelist <- left_join(multi_author, | |
select(articles, `dc:identifier`, faculty)) |> | |
rename(id = `dc:identifier`) %>% | |
group_by(id) |> | |
mutate(i = 1:n()) |> | |
pivot_wider(names_from = i, values_from = "faculty") | |
edgelist_3 <- filter(edgelist, !is.na(`3`)) %>% | |
split(.$id) %>% | |
map_df(function(x) { | |
tibble(id = x$id, | |
n_authors = 3, | |
`1` = c(x$`1`[1], x$`1`[1]), | |
`2` = c(x$`2`[1], x$`3`[1])) | |
}) | |
edgelist_2 <- filter(edgelist, is.na(`3`)) |> | |
arrange(id) | |
edgelist_full <- edgelist_2 |> | |
bind_rows(edgelist_3) |> | |
ungroup() |> | |
select(`1`,`2`) |> | |
group_by(`1`,`2`) |> | |
count() | |
mat <- as.matrix(edgelist_full[,1:2], ncol = 2) | |
g <- graph_from_edgelist(mat, directed=FALSE) | |
area <- as.factor(unlist(map(names(V(g)), | |
function(x) {filter(faculty, last == x)$area}))) | |
GGally::ggnet2(g, | |
label = TRUE, | |
mode = "kamadakawai", | |
node.color = area, | |
edge.size = edgelist_full$n/3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment