【问题标题】:r igraph - how does plot() read the layout matrix?r igraph - plot() 如何读取布局矩阵?
【发布时间】:2020-09-13 23:36:19
【问题描述】:

我的问题与here 相关,遗憾的是尚未得到回复。我正在尝试自动注释情节上突出显示的社区旁边的文本。中间步骤是了解节点如何放置在图上。

G <- make_graph('zachary')
l <- layout_with_fr(G)
l

布局是一个矩阵,其中行代表节点,列代表 x 和 y 绘图参数。

           [,1]       [,2]
 [1,] 2.8510654 -2.2404898
 [2,] 2.7183497 -1.1815130
 [3,] 3.1429205  0.1117099
 [4,] 1.5585372 -1.0743325
 [5,] 2.2808632 -4.2035479
 [6,] 2.1698198 -5.0526766
 [7,] 1.4938068 -4.6975884
 [8,] 1.9710816 -1.4672218
 [9,] 3.5407035  0.5407852
[10,] 2.2222909  1.9079805
[11,] 3.0784642 -4.5828448
[12,] 4.4115351 -4.1057462
[13,] 0.6002378 -2.2432049
[14,] 2.5010525 -0.1563341
[15,] 4.8914673  4.1417759
[16,] 3.2053338  3.9212694
[17,] 1.1825200 -6.4099021
[18,] 3.7155897 -2.8354432
[19,] 3.8272351  4.2660906
[20,] 3.8636487 -0.5671906
[21,] 2.7302411  3.3998888
[22,] 1.6084374 -2.7407388
[23,] 4.3432855  3.8101278
[24,] 5.9392042  2.2364929
[25,] 6.9980077  0.2389222
[26,] 7.1608499  1.1360134
[27,] 6.0171481  4.0279067
[28,] 5.4996627  1.0367163
[29,] 4.4961257  0.9434659
[30,] 5.5987563  3.2314488
[31,] 2.9958404  1.2022317
[32,] 5.1188900  0.2919268
[33,] 4.1088296  2.5032294
[34,] 4.1686534  2.1339884

但绘图的 x、y 坐标从 -1 变为 1,这与布局矩阵中的最小-最大坐标不同。那么plot(G, layout = l)是如何读取布局矩阵的呢?

【问题讨论】:

    标签: r igraph


    【解决方案1】:

    根据the sourceigraph 类对象的绘图方法只是将矩阵从-1 重新缩放为1

    library(igraph)
    set.seed(3)
    l <- layout_with_fr(G)
            [,1]   [,2]
     [1,] -2.283  0.658
     [2,] -1.289 -0.108
     [3,]  0.146  1.012
     [4,] -1.523  1.601
    #... with 30 more rows.
    plot(G,layout = l)
    

    maxs <- apply(l, 2, max)
    mins <- apply(l, 2, min)
    ll <- scale(l, center=(maxs+mins)/2, scale=(maxs-mins)/2)
    ll
             [,1]    [,2]
     [1,] -0.2422 -0.1051
     [2,] -0.0704 -0.3821
     [3,]  0.1775  0.0228
     [4,] -0.1108  0.2357
    #... with 30 more rows.
    plot(G,layout = ll)
    

    请注意,实际的缩放是使用igraph::norm_coords 执行的:

    igraph::norm_coords(l)
             [,1]    [,2]
     [1,] -0.2422 -0.1051
     [2,] -0.0704 -0.3821
     [3,]  0.1775  0.0228
     [4,] -0.1108  0.2357
    #... with 30 more rows.
    

    【讨论】:

      猜你喜欢
      • 2017-04-17
      • 2018-07-03
      • 2016-10-11
      • 2018-12-07
      • 1970-01-01
      • 2022-11-14
      • 1970-01-01
      • 2013-03-18
      相关资源
      最近更新 更多