【问题标题】:r igraph plot layout error: incorrect number of subscripts on matrixr igraph 绘图布局错误:矩阵上的下标数量不正确
【发布时间】:2016-10-11 15:53:39
【问题描述】:

我正在尝试手动设置 igraph 图的顶点坐标。坐标代表纬度和经度值。我不断收到错误:

Error in ec[, 3:4] <- t(sapply(seq(length = nrow(el)), function(x) { : 
incorrect number of subscripts on matrix

这是我正在使用的对象/变量:

图形对象-

    > g_mat_cut
IGRAPH UNW- 28 88 -- 
+ attr: name (v/c), shape (v/c), color (v/c), weight (e/n)
+ edges (vertex names):
 [1] 010C10AB53--010C10CA44 010C10AB53--010C10D28B 010C10AB53--010C10D28E
 [4] 010C10AB53--010C10EA1E 010C10AB53--010C1108EB 010C10AB53--010C11169A
 [7] 010C10AB53--010C112145 010C10AB53--010C117822 010C10AB53--010C117E53
[10] 010C10AB53--010C1180A0 010C10AB53--010C11922B 010C10AB53--010C11B911
[13] 010C10AB53--010C11BBA6 010C10AB53--010C11BC8D 010C10AB53--010C11BEB7
[16] 010C10C3A5--010C116DC1 010C10CA44--010C10D28B 010C10CA44--010C114E81
[19] 010C10CA44--010C11B911 010C10CA44--010C11BBA6 010C10CBBD--010C117822
[22] 010C10D28B--010C10D28E 010C10D28B--010C1108EB 010C10D28B--010C11169A
+ ... omitted several edges

具有以下顶点属性 -

 vertex.attributes(g_mat_cut)
$name
 [1] "010C10AB53" "010C10BEA5" "010C10C3A5" "010C10CA44" "010C10CBBD"
 [6] "010C10D28B" "010C10D28E" "010C10EA1E" "010C10EFE8" "010C11059F"
[11] "010C1108EB" "010C1111B5" "010C111428" "010C11169A" "010C112145"
[16] "010C114E81" "010C115391" "010C116DC1" "010C117822" "010C117E53"
[21] "010C1180A0" "010C11922B" "010C119C7E" "010C11A61D" "010C11B911"
[26] "010C11BBA6" "010C11BC8D" "010C11BEB7"

$shape
 [1] "circle" "square" "square" "square" "square" "square" "square" "square"
 [9] "circle" "square" "square" "square" "square" "square" "square" "circle"
[17] "circle" "circle" "circle" "circle" "square" "square" "square" "square"
[25] "square" "circle" "square" "circle"

$color
 [1] "#99D594" "#3288BD" "#3288BD" "#3288BD" "#99D594" "#99D594" "#3288BD"
 [8] "#3288BD" "#D53E4F" "#D53E4F" "#99D594" "#3288BD" "#3288BD" "#3288BD"
[15] "#3288BD" "#3288BD" "#D53E4F" "#D53E4F" "#3288BD" "#3288BD" "#3288BD"
[22] "#99D594" "#3288BD" "#99D594" "#3288BD" "#3288BD" "#FEE08B" "#FEE08B"

顶点位置的空间坐标:

 coords
          [,1]      [,2]
 [1,] 50.19954 -5.169506
 [2,] 50.19866 -5.168653
 [3,] 50.19853 -5.169905
 [4,] 50.19856 -5.168397
 [5,] 50.19954 -5.169506
 [6,] 50.19794 -5.168535
 [7,] 50.19833 -5.169241
 [8,] 50.19897 -5.169436
 [9,] 50.19915 -5.169564
[10,] 50.19908 -5.169429
[11,] 50.19878 -5.169403
[12,] 50.19857 -5.170018
[13,] 50.19859 -5.168570
[14,] 50.19847 -5.169863
[15,] 50.19982 -5.171222
[16,] 50.19866 -5.168653
[17,] 50.19844 -5.168694
[18,] 50.19794 -5.168535
[19,] 50.19833 -5.169241
[20,] 50.19781 -5.168733
[21,] 50.19855 -5.168908
[22,] 50.19915 -5.169564
[23,] 50.20034 -5.170551
[24,] 50.19878 -5.169697
[25,] 50.19882 -5.170664
[26,] 50.19982 -5.171222
[27,] 50.19838 -5.170642
[28,] 50.19841 -5.169932

str(coords)
num [1:28, 1:2] 50.2 50.2 50.2 50.2 50.2 ...

attempt at plotting:

   plot(g_mat_cut,layout=coords,vertex.size=4,rescale=FALSE,xlim=c(50.19,50.21),ylim=c(-5.16,-5.18))
Error in ec[, 3:4] <- t(sapply(seq(length = nrow(el)), function(x) { : 
incorrect number of subscripts on matrix

【问题讨论】:

    标签: r layout plot geospatial igraph


    【解决方案1】:

    我无法真正回答您的问题,但也许我尝试过的事情可以帮助您。

    我有同样的问题,因为我尝试在某些顶点上使用与圆形不同的顶点形状。 具有不同的顶点形状并且不指定布局矩阵可以正常工作。并且拥有所有vertex.shape = "circle" 并指定布局矩阵也可以。设置vertex.shape = "square" 并尝试使用布局矩阵进行绘图 - 不可重现 - 行:

    plot(gBase, layout=matrix(c(as.numeric(V(gBase)$lon), as.numeric(V(gBase)$lat)), ncol=2), vertex.label=NA, vertex.shape = "square", vertex.size = as.numeric(V(gBase)$size), vertex.size2=as.numeric(V(gBase)$size2))

    给出这个错误:

    Error in y1 - y2 : non-numeric argument to binary operator

    如您所见,我已经尝试将尺寸和布局强制为数字(尽管它们从一开始就设置为数字值)。您也可以将vertex.shape = "circle" 替换为vertex.shape = "rectangle",这样.size2 才有意义。错误将是相同的。

    因此,我认为问题在于定位形状为“正方形”或“矩形”的顶点。

    documentation 中,只有一个使用形状和已定义布局进行绘图的示例,但对我没有帮助。

    【讨论】:

      猜你喜欢
      • 2017-02-20
      • 2021-01-05
      • 1970-01-01
      • 2016-04-27
      • 2020-03-05
      • 2020-09-13
      • 2020-03-04
      • 1970-01-01
      • 2021-11-07
      相关资源
      最近更新 更多