A network plot of linked publications using DOIs and ORCiDs using D3.js based on Mike Bostock's force-directed graph here and DOI/ORCiD code initially presented here. The R back-end is a bit messy still. The hardest part was getting it into a JSON format that would work with d3.js
.
Using the code on downwithtime
you can append this block immediately after defining the vector of unique DOIs. It's still ugly, but it works.
to_json <- list(links = list(),
nodes = data.frame(all.df[!duplicated(all.df$orcid),-1]))
for(i in 1:length(unique.dois)){
doi <- unique.dois[i]
authors <- all.df$name[all.df$doi %in% doi]
if(length(authors) > 1){
combi <- data.frame(t(combn(all.df$name[all.df$doi %in% unique.dois[i]], 2)),
width = 1)
combi[,1] <- match(combi[,1], to_json$nodes$name)
combi[,2] <- match(combi[,2], to_json$nodes$name)
to_json$links[[i]] <- combi
}
}
to_json$links <- do.call(rbind.data.frame, to_json$links)
colnames(to_json$links) <- c('source', 'target', 'width')
to_json$links <- to_json$links %>% group_by(source, target) %>% summarise(sum(width))
colnames(to_json$links) <- c('source', 'target', 'width')
# There is a problem with the numbering because we don't get a consistent 1-n numbering that
# d3 expects.
# Here we reorder everything:
unique_source <- data.frame(news = 1:nrow(unique(to_json$links[,1])),
olds = unlist(unique(to_json$links[,1])))
not_source <- to_json$links$target[!to_json$links$target %in% to_json$links$source]
target_source <- data.frame(news= 1:length(not_source) + max(unique_source$news),
olds = not_source)
resorter <- rbind.data.frame(unique_source, target_source)
to_json$nodes <- to_json$nodes[(resorter$olds),]
to_json$links$source <- match(to_json$links$source, resorter$olds)
to_json$links$target <- match(to_json$links$target, resorter$olds)
cat(jsonlite::toJSON(to_json), file = 'authors.json')
Hey @BillMills I got it to work :)
http://bl.ocks.org/SimonGoring/6d499c40e8f222d2146d
A lot of it was problems with the JSON that I didn't anticipate. Partly I forgot that indexing in R is different than in js. That 0/1 thing really messed me up for a while!