我正在使用igraph软件包按如下方式绘制网络,但我希望能够显示图中的所有节点(作者),甚至是那些与他人没有共同论文的作者。有可能吗?
PubID <- c("169759","174843","174843","174843","174843","174843","171051","171051","171051","171719","171719","171719","169759","173847","173847","177427")
Author <- c("ZJ","RA","DJ","JP","GS","Tv","MC","JR","CW","PB","MD","FO","FO","RA","DJ","KS")
dt <- data.frame(Author,PubID)
library(tidyverse)
library(igraph)
dt %>%
mutate(author_id = as.integer(Author)) -> dt
dt %>%
inner_join(dt, by = "PubID") %>%
filter(author_id.x < author_id.y) %>%
count(Author.x, Author.y) %>%
graph_from_data_frame(directed = FALSE) -> g1
plot(g1)
as_data_frame(g1, what = "edges")
我想显示网络,然后将“ KS”作者显示为图中的单个节点。
答案 0 :(得分:1)
首先,我们找到所有尚未出现的人:
(rest <- setdiff(Author, V(g1)$name))
# [1] "KS"
然后添加它们
g1 <- add.vertices(g1, length(rest), attr = list(name = rest))