我无法在 R 中的 igraph 中为我的网络图添加边
I can't add edges to my network graph made in the igraph in R
我想通过igraph做一个网络图,但是只有节点出现,边/链接没有出现。我的数据来自邻接矩阵。而且我不知道问题出在哪里。有谁知道如何添加边缘?
这是我的脚本:
library(igraph)
data = structure(list(Adenocalymma_adenophorum = c(NA, 0, 0, 0, 0.003122927,
0.00999241, 0.008685473, 0.007730365, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0.003573423, 0, 0, 0, 0, 0), Adenocalymma_cf_bracteosum = c(0L,
NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L), Adenocalymma_flaviflorum = c(0L, 0L,
NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L), Adenocalymma_japurensis = c(0L, 0L, 0L,
NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L), Adenocalymma_longilinium = c(0.18893711, 0,
0, 0, NA, 0.183237263, 0.139293056, 0.120902907, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0.132071652, 0, 0.457142857, 0.114500717
), Adenocalymma_moringifolium = c(0.322255215, 0, 0, 0, 0.097676062,
NA, 0.261095249, 0.131416203, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.146191646,
0, 0, 0, 0), Adenocalymma_neoflavidum = c(0.086854728, 0, 0,
0, 0.023023646, 0.080959767, NA, 0.034786642, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Adenocalymma_tanaeciicarpum = c(0.09469697,
0, 0, 0, 0.024480341, 0.049917782, 0.042613636, NA, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0.255554962, 0, 0, 0, 0), Amphilophium_parkeri = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L), Anemopaegma_robustum = c(0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L), Bignonia_aequinoctialis = c(0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L), Bignonia_prieurei = c(0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
), Calichlamys_latifolia = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L),
Fridericia_cf_trailli = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.765625,
0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0), Fridericia_chica = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, NA, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L), Fridericia_cinamomea = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, NA,
0L, 0L, 0L, 0L, 0L, 0L, 0L), Fridericia_nigrescens = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
NA, 0L, 0L, 0L, 0L, 0L, 0L), Fridericia_prancei = c(0.040201005,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0,
0, 0, 0), Fridericia_triplinervia = c(0, 0, 0, 0, 0, 0.041930937,
0, 0.192970073, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0,
0), Pachyptera_aromatica = c(0, 0, 0, 0, 0.030562035, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0), Pleonotoma_albiflora = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, NA, 0L, 0L), Pleonotoma_melioides = c(0,
0, 0, 0, 0.151121606, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, NA, 0.039751553), Tynanthus_panurensis = c(0,
0, 0, 0, 0, 0.026693325, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0.011428571, NA)), class = "data.frame", row.names = c("Adenocalymma_adenophorum",
"Adenocalymma_cf_bracteosum", "Adenocalymma_flaviflorum", "Adenocalymma_japurensis",
"Adenocalymma_longilinium", "Adenocalymma_moringifolium", "Adenocalymma_neoflavidum",
"Adenocalymma_tanaeciicarpum", "Amphilophium_parkeri", "Anemopaegma_robustum",
"Bignonia_aequinoctialis", "Bignonia_prieurei", "Calichlamys_latifolia",
"Fridericia_cf_trailli", "Fridericia_chica", "Fridericia_cinamomea",
"Fridericia_nigrescens", "Fridericia_prancei", "Fridericia_triplinervia",
"Pachyptera_aromatica", "Pleonotoma_albiflora", "Pleonotoma_melioides",
"Tynanthus_panurensis"))
View (data)
class (data)
data= data.matrix(data, rownames.force = NA) #
class (data)
network <- graph_from_adjacency_matrix (data)
plot(network, edge.arrow.size=.5, vertex.color="gold", vertex.size=15,
vertex.frame.color="gray", vertex.label.color="black",
vertex.label.cex=0.8, vertex.label.dist=2, edge.curved=0.2)
当我运行网络时,出现如下:
IGRAPH 52a911a DN-- 23 0 --
+ attr: name (v/c)
+ edges from 52a911a (vertex names)
我的图表:
graph
谢谢。
我认为你应该启用参数选项 mode =
和 weighted
graph <- graph_from_adjacency_matrix(data, mode = "directed", weighted = TRUE)
然后 plot(graph)
给你
我想通过igraph做一个网络图,但是只有节点出现,边/链接没有出现。我的数据来自邻接矩阵。而且我不知道问题出在哪里。有谁知道如何添加边缘?
这是我的脚本:
library(igraph)
data = structure(list(Adenocalymma_adenophorum = c(NA, 0, 0, 0, 0.003122927,
0.00999241, 0.008685473, 0.007730365, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0.003573423, 0, 0, 0, 0, 0), Adenocalymma_cf_bracteosum = c(0L,
NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L), Adenocalymma_flaviflorum = c(0L, 0L,
NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L), Adenocalymma_japurensis = c(0L, 0L, 0L,
NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L), Adenocalymma_longilinium = c(0.18893711, 0,
0, 0, NA, 0.183237263, 0.139293056, 0.120902907, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0.132071652, 0, 0.457142857, 0.114500717
), Adenocalymma_moringifolium = c(0.322255215, 0, 0, 0, 0.097676062,
NA, 0.261095249, 0.131416203, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.146191646,
0, 0, 0, 0), Adenocalymma_neoflavidum = c(0.086854728, 0, 0,
0, 0.023023646, 0.080959767, NA, 0.034786642, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Adenocalymma_tanaeciicarpum = c(0.09469697,
0, 0, 0, 0.024480341, 0.049917782, 0.042613636, NA, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0.255554962, 0, 0, 0, 0), Amphilophium_parkeri = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L), Anemopaegma_robustum = c(0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L), Bignonia_aequinoctialis = c(0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L), Bignonia_prieurei = c(0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
), Calichlamys_latifolia = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L),
Fridericia_cf_trailli = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.765625,
0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0), Fridericia_chica = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, NA, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L), Fridericia_cinamomea = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, NA,
0L, 0L, 0L, 0L, 0L, 0L, 0L), Fridericia_nigrescens = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
NA, 0L, 0L, 0L, 0L, 0L, 0L), Fridericia_prancei = c(0.040201005,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0,
0, 0, 0), Fridericia_triplinervia = c(0, 0, 0, 0, 0, 0.041930937,
0, 0.192970073, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0,
0), Pachyptera_aromatica = c(0, 0, 0, 0, 0.030562035, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0), Pleonotoma_albiflora = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, NA, 0L, 0L), Pleonotoma_melioides = c(0,
0, 0, 0, 0.151121606, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, NA, 0.039751553), Tynanthus_panurensis = c(0,
0, 0, 0, 0, 0.026693325, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0.011428571, NA)), class = "data.frame", row.names = c("Adenocalymma_adenophorum",
"Adenocalymma_cf_bracteosum", "Adenocalymma_flaviflorum", "Adenocalymma_japurensis",
"Adenocalymma_longilinium", "Adenocalymma_moringifolium", "Adenocalymma_neoflavidum",
"Adenocalymma_tanaeciicarpum", "Amphilophium_parkeri", "Anemopaegma_robustum",
"Bignonia_aequinoctialis", "Bignonia_prieurei", "Calichlamys_latifolia",
"Fridericia_cf_trailli", "Fridericia_chica", "Fridericia_cinamomea",
"Fridericia_nigrescens", "Fridericia_prancei", "Fridericia_triplinervia",
"Pachyptera_aromatica", "Pleonotoma_albiflora", "Pleonotoma_melioides",
"Tynanthus_panurensis"))
View (data)
class (data)
data= data.matrix(data, rownames.force = NA) #
class (data)
network <- graph_from_adjacency_matrix (data)
plot(network, edge.arrow.size=.5, vertex.color="gold", vertex.size=15,
vertex.frame.color="gray", vertex.label.color="black",
vertex.label.cex=0.8, vertex.label.dist=2, edge.curved=0.2)
当我运行网络时,出现如下:
IGRAPH 52a911a DN-- 23 0 --
+ attr: name (v/c)
+ edges from 52a911a (vertex names)
我的图表: graph
谢谢。
我认为你应该启用参数选项 mode =
和 weighted
graph <- graph_from_adjacency_matrix(data, mode = "directed", weighted = TRUE)
然后 plot(graph)
给你