我有一个dataframe nodes
,组信息如下:
dput(nodes)
structure(list(id = c("AC006329.1", "AC027796.4", "AC111170.2",
"AC111170.3", "AC138207.4", "AP000695.2", "CDK15", "COL14A1",
"COL15A1", "DDX11-AS1", "FOXP4-AS1", "IFNG-AS1", "ITGB2-AS1",
"LINC00944", "LINC01213", "LINC01395", "MIR155HG", "MSTRG.108144",
"MSTRG.110466", "MSTRG.11483", "MSTRG.130624", "MSTRG.134576",
"MSTRG.147129", "MSTRG.180740", "MSTRG.180762", "MSTRG.24184",
"MSTRG.9061", "SERHL"), label = c("AC006329.1", "AC027796.4",
"AC111170.2", "AC111170.3", "AC138207.4", "AP000695.2", "CDK15",
"COL14A1", "COL15A1", "DDX11-AS1", "FOXP4-AS1", "IFNG-AS1", "ITGB2-AS1",
"LINC00944", "LINC01213", "LINC01395", "MIR155HG", "MSTRG.108144",
"MSTRG.110466", "MSTRG.11483", "MSTRG.130624", "MSTRG.134576",
"MSTRG.147129", "MSTRG.180740", "MSTRG.180762", "MSTRG.24184",
"MSTRG.9061", "SERHL"), group = structure(c(1L, 6L, 6L, 6L, 4L,
3L, 4L, 4L, 4L, 1L, 1L, 2L, 2L, 2L, 5L, 5L, 2L, 4L, 2L, 1L, 6L,
5L, 5L, 3L, 3L, 3L, 1L, 5L), levels = c("blue", "brown", "cyan",
"green", "purple", "red"), class = "factor")), row.names = c(NA,
-28L), class = "data.frame")
字符串edges
看起来像下面这样:
下面是edges.csv文件
使用nodes
和edges
,我使用以下代码创建网络图:
当我像下面这样使用时,网络图一直在移动,根本不会停止。
visNetwork(nodes, edges)
型
我也试着把visPhysics(stabilization = FALSE)
添加到上面的行中,但没有工作。
所以,我尝试了下面的igraph布局:
visNetwork(nodes, edges) %>%
visIgraphLayout()
型
x1c 0d1x的数据
这不会将来自同一组的节点保持在一起。谁能告诉我如何将同一组/颜色的节点保存在一起?
它应该看起来像下面这样:
的
2条答案
按热度按时间lsmepo6l1#
我通常发现使用
tidygraph
和ggraph
生态系统定制网络图更容易。您的图形具有比给定示例更多的边,因此可能需要进行一些调整以使边看起来像您想要的那样。字符串
的数据
编辑
要调整布局,使组之间不会太近,并以清晰的方式标记节点,您可以执行以下操作:
型
的
piv4azn72#
这就是我对
igraph
的尝试字符串
然后把它画出来
型
的数据