1

我坚持在 R 上绘制图表。特别是,我想制作一个网络图 一

但是使用另一种颜色的中心节点和其他节点的大小与数据集中的列权重一样大。数据集如下:

structure(list(owner = c("MASTERS", "MASTERS", "MASTERS", "MASTERS", "MASTERS", "MASTERS","MASTERS", "MASTERS"), 
armed_band = c("Biakatu Communal Militia", "FPJC", "FRPI", "LRA", "Mayi Mayi Militia", "Mayi Mayi Militia (Safisha Mabaya)", "Mayi Mayi Militia (Simba)", "RCD"), 
weigth = c(1, 1, 1, 5, 2, 1, 1, 1)), 
row.names = c(NA, -8L), 
class = c("tbl_df", "tbl", "data.frame")) 

我目前使用的代码如下:

aux_samearea_network <- read_excel("file") 
concessions_network = network(aux_samearea_network, 
                     matrix.type = "edgelist", 
                     ignore.eval = FALSE,
                     names.eval = "weights" ) 

concessions_network %v% "Concession" = ifelse(
aux_samearea_network$armed_band %in% c("LRA",
"Mayi Mayi Militia", 
"Biakatu Communal Militia",
"FPJC",
"FRPI",
"Mayi Mayi Militia (Safisha Mabaya)",
"Mayi Mayi Militia (Simba)",
"RCD"), "Armed Band", "Concession")

ggnet2(concessions_network, 
   node.size = "weights", 
   node.color = "lightblue", 
   edge.size = 1, 
   edge.color = "grey",
   main = "Network concession MASTERS",
   edge.label = "weights",
   label = TRUE,)

任何人都可以帮我解决这个问题吗?我将不胜感激。

4

1 回答 1

1

我想你可以尝试igraph如下

library(igraph)
g <- graph_from_data_frame(aux_samearea_network)
V(g)$color <- factor(V(g)$name %in% aux_samearea_network$owner)
plot(g,
  edge.width = aux_samearea_network$weigth,
  edge.label = aux_samearea_network$weigth
)

我们会得到 在此处输入图像描述

于 2020-09-12T22:03:16.593 回答