我使用igraph_to_networkD3()转换了我的igraph对象,以便能够使用forceNetwork绘图。然而,我的V3列中有-1和1,表示与我的igraph对象的负相关和正相关,我不再能像在simpleNetwork中那样通过相关性为边缘着色。
我尝试将列添加到links data.frame中,但是链接现在的顺序与它们在原始igraph对象中的顺序不同,因此相关性不再与正确的边匹配。另外,我的igraph对象中的原始边列表不是数字的,所以我不能在forceNetwork中使用它。
如何通过相关性来着色,而无需手动查看每个边缘?我希望能够使用forceNetwork而不是simpleNetwork来更改节点大小并添加图例。
这是我的原始igraph对象的样子:
IGRAPH 6384c93 UN-- 52 88 --
+ attr: name (v/c), X3 (e/c), color (e/c)
+ edges from 6384c93 (vertex names):
[1] k__Bacteria;p__Proteobacteria;c__Alphaproteobacteria;o__Rickettsiales;f__mitochondria;__--k__Bacteria;p__Firmicutes;c__Bacilli;o__Bacillales;f__Paenibacillaceae;__
[2] k__Bacteria;p__Proteobacteria;c__Alphaproteobacteria;o__Rickettsiales;f__mitochondria;__--k__Bacteria;p__Proteobacteria;c__Gammaproteobacteria;o__Xanthomonadales;f__Xanthomonadaceae;g__Stenotrophomonas
[3] k__Bacteria;p__Proteobacteria;c__Alphaproteobacteria;o__Rickettsiales;f__mitochondria;__--k__Bacteria;p__Proteobacteria;c__Alphaproteobacteria;o__Rhizobiales;__;__
[4] k__Bacteria;p__Cyanobacteria;c__Chloroplast;o__Streptophyta;f__;g__ --k__Bacteria;p__Proteobacteria;c__Alphaproteobacteria;o__Sphingomonadales;f__Sphingomonadaceae;__
[5] k__Bacteria;p__Cyanobacteria;c__Chloroplast;o__Streptophyta;f__;g__ --k__Bacteria;p__Bacteroidetes;c__Sphingobacteriia;o__Sphingobacteriales;f__Sphingobacteriaceae;g__Mucilaginibacter
X1
1 k__Bacteria;p__Proteobacteria;c__Alphaproteobacteria;o__Rickettsiales;f__mitochondria;__
2 k__Bacteria;p__Proteobacteria;c__Alphaproteobacteria;o__Rickettsiales;f__mitochondria;__
3 k__Bacteria;p__Proteobacteria;c__Alphaproteobacteria;o__Rickettsiales;f__mitochondria;__
4 k__Bacteria;p__Cyanobacteria;c__Chloroplast;o__Streptophyta;f__;g__
5 k__Bacteria;p__Cyanobacteria;c__Chloroplast;o__Streptophyta;f__;g__
X2 X3
1 k__Bacteria;p__Firmicutes;c__Bacilli;o__Bacillales;f__Paenibacillaceae;__ -1
2 k__Bacteria;p__Proteobacteria;c__Gammaproteobacteria;o__Xanthomonadales;f__Xanthomonadaceae;g__Stenotrophomonas -1
3 k__Bacteria;p__Proteobacteria;c__Alphaproteobacteria;o__Rhizobiales;__;__ -1
4 k__Bacteria;p__Proteobacteria;c__Alphaproteobacteria;o__Sphingomonadales;f__Sphingomonadaceae;__ -1
5 k__Bacteria;p__Bacteroidetes;c__Sphingobacteriia;o__Sphingobacteriales;f__Sphingobacteriaceae;g__Mucilaginibacter -1
这是我的新networkd 3边缘列表的样子:
source target
22 31
29 31
8 19
3 36
6 36
20 36
12 36
37 43
26 43
38 43
这是我的代码
# Create a networkD3 graph object from igraph object, group by bacteria vs fungi
netd3 <- igraph_to_networkD3(sparcc.graph, group = ifelse(grepl("Bacteria", V(sparcc.graph)$name), "Bacteria", "Fungi"))
# Add node size based on betweenness to nodes
netd3$nodes <- data.frame(cbind(netd3$nodes, nodesize = sqrt(betweenness(sparcc.graph)/3)))
# Create a color scale for plotting
color_func <- ('d3.scaleOrdinal().range(["#AC88FF", "#E7861B"]);')
# Generate an interactive visualization using forceNetwork
forceNetwork(Links = netd3$links, Nodes = netd3$nodes, Source = "source", Target = "target", NodeID = "name", Group = "group", legend = TRUE, colourScale = JS(color_func), Nodesize = "nodesize", zoom = TRUE,)
1条答案
按热度按时间zujrkrfu1#
igraph::get.edge.attribute()
可能会有帮助?