用运动网络覆盖空间地图的问题
Problems with overlaying the spatial map with a movement network
为了在空间地图上叠加运动网络,我尝试使用 igraph、ggraph 和 ggplot2 包等定义自己的自定义布局,以将地理坐标绘制为节点位置。下面的代码曾经可以工作,但现在不行了。也许是因为我更新了软件包,但我不记得了。我不知道如何解决我在下面收到的错误消息。非常感谢任何解决问题的帮助。
创建自定义布局的相关代码如下。
igraph 图 'g':
g<-structure(list(32, FALSE, c(1, 4, 5, 6, 7, 8, 9, 10, 11, 13,
14, 15, 18, 19, 20, 22, 25, 27, 28, 31, 4, 6, 7, 9, 18, 22, 6,
7, 9, 13, 14, 18, 27, 9, 18, 7, 8, 9, 18, 22, 27, 9, 18, 10,
17, 18, 22, 27, 18, 18, 22, 18, 22, 27, 27), c(0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
4, 4, 4, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
9, 10, 13, 13, 14, 18, 18, 22), c(0, 1, 20, 2, 3, 21, 26, 4,
22, 27, 35, 5, 36, 6, 23, 28, 33, 37, 41, 7, 43, 8, 9, 29, 10,
30, 11, 44, 12, 24, 31, 34, 38, 42, 45, 48, 49, 51, 13, 14, 15,
25, 39, 46, 50, 52, 16, 17, 32, 40, 47, 53, 54, 18, 19), c(0,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
51, 52, 53, 54), c(0, 0, 1, 1, 1, 3, 4, 7, 11, 13, 19, 21, 22,
22, 24, 26, 27, 27, 28, 38, 39, 40, 40, 46, 46, 46, 47, 47, 53,
54, 54, 54, 55), c(0, 20, 26, 26, 26, 33, 35, 36, 41, 43, 48,
49, 49, 49, 51, 52, 52, 52, 52, 54, 54, 54, 54, 55, 55, 55, 55,
55, 55, 55, 55, 55, 55), list(c(1, 0, 1), structure(list(), .Names = character(0)),
list(name = c("1", "2", "3", "4", "5", "6", "7", "8", "9",
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
"20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
"30", "31", "32"), long = c(-79.260866474359, -80.0214733333333,
-76.7089527272727, -74.780105, -80.2763261538462, -80.46082,
-80.030754125, -80.121487, -82.1419016578947, -81.41021461,
-85.6918532152941, -81.2031545454546, -81.187526, -80.11719,
-80.5063443067816, -82.5245573333333, -78.8618875, -80.883413,
-79.7296606, -76.9488, -77.8201766666667, -76.5490625, -81.5434341458974,
-93.59755, -88.035675, -83.2922209874074, -84.5110066666667,
-79.1122080625, -80.173172, -77.3383016666667, -78.2188216666667,
-77.7654788888889), lat = c(25.7205797179487, 26.85296, 25.53793,
38.33654, 27.1842307692308, 24.948536, 26.99901625, 27.171273,
28.2081715526316, 24.6188354115741, 29.4212288229412, 31.0068890909091,
29.643964, 26.6099285714286, 28.4826687301149, 27.100245,
26.63643, 31.3834996666667, 32.6213106, 34.2073, 24.8982166666667,
24.3104225, 24.6719581623077, 27.90902, 30.0528425, 27.764016172963,
29.706515, 26.97782228125, 25.5103912857143, 34.55239, 26.6567083333333,
26.9487844444444)), list(weight = c(426, 58, 3, 253, 493,
9, 392, 7, 4, 42, 5, 2, 40, 1, 2, 74, 2, 106, 17, 1, 2, 114,
62, 9, 1, 1, 1, 5, 3, 12, 1, 9, 1, 2, 1, 1, 1, 15, 6, 2,
17, 4, 1, 1, 1, 21, 4, 4, 1, 1, 1, 1, 2, 1, 2))), <environment>), class = "igraph")
节点位置:
nodes_pos<-structure(list(x = c(-79.260866474359, -80.0214733333333, -76.7089527272727,
-74.780105, -80.2763261538462, -80.46082, -80.030754125, -80.121487,
-82.1419016578947, -81.41021461, -85.6918532152941, -81.2031545454546,
-81.187526, -80.11719, -80.5063443067816, -82.5245573333333,
-78.8618875, -80.883413, -79.7296606, -76.9488, -77.8201766666667,
-76.5490625, -81.5434341458974, -93.59755, -88.035675, -83.2922209874074,
-84.5110066666667, -79.1122080625, -80.173172, -77.3383016666667,
-78.2188216666667, -77.7654788888889), y = c(25.7205797179487,
26.85296, 25.53793, 38.33654, 27.1842307692308, 24.948536, 26.99901625,
27.171273, 28.2081715526316, 24.6188354115741, 29.4212288229412,
31.0068890909091, 29.643964, 26.6099285714286, 28.4826687301149,
27.100245, 26.63643, 31.3834996666667, 32.6213106, 34.2073, 24.8982166666667,
24.3104225, 24.6719581623077, 27.90902, 30.0528425, 27.764016172963,
29.706515, 26.97782228125, 25.5103912857143, 34.55239, 26.6567083333333,
26.9487844444444)), row.names = 1:32, class = "data.frame")
手动布局:
lay <- create_layout(graph = g, layout = "manual",
node.positions = nodes_pos)
错误信息
Error in layout_fun(graph, circular = circular, ...) :
unused argument (node.positions = nodes_pos)
包版本:
- ggraph 2.0.2
- igraph 1.2.4.2
- R 3.6.2
尝试:
g_new <- upgrade_graph(g)
lay <- create_layout(g_new, 'manual',
x = long, y = lat)
ggraph(lay) +
geom_node_point(color = "red") +
geom_polygon(data = map_data("state"), aes(x=long, y=lat, group=group),
color="black", fill="lightblue" )
为了在空间地图上叠加运动网络,我尝试使用 igraph、ggraph 和 ggplot2 包等定义自己的自定义布局,以将地理坐标绘制为节点位置。下面的代码曾经可以工作,但现在不行了。也许是因为我更新了软件包,但我不记得了。我不知道如何解决我在下面收到的错误消息。非常感谢任何解决问题的帮助。
创建自定义布局的相关代码如下。
igraph 图 'g':
g<-structure(list(32, FALSE, c(1, 4, 5, 6, 7, 8, 9, 10, 11, 13,
14, 15, 18, 19, 20, 22, 25, 27, 28, 31, 4, 6, 7, 9, 18, 22, 6,
7, 9, 13, 14, 18, 27, 9, 18, 7, 8, 9, 18, 22, 27, 9, 18, 10,
17, 18, 22, 27, 18, 18, 22, 18, 22, 27, 27), c(0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
4, 4, 4, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
9, 10, 13, 13, 14, 18, 18, 22), c(0, 1, 20, 2, 3, 21, 26, 4,
22, 27, 35, 5, 36, 6, 23, 28, 33, 37, 41, 7, 43, 8, 9, 29, 10,
30, 11, 44, 12, 24, 31, 34, 38, 42, 45, 48, 49, 51, 13, 14, 15,
25, 39, 46, 50, 52, 16, 17, 32, 40, 47, 53, 54, 18, 19), c(0,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
51, 52, 53, 54), c(0, 0, 1, 1, 1, 3, 4, 7, 11, 13, 19, 21, 22,
22, 24, 26, 27, 27, 28, 38, 39, 40, 40, 46, 46, 46, 47, 47, 53,
54, 54, 54, 55), c(0, 20, 26, 26, 26, 33, 35, 36, 41, 43, 48,
49, 49, 49, 51, 52, 52, 52, 52, 54, 54, 54, 54, 55, 55, 55, 55,
55, 55, 55, 55, 55, 55), list(c(1, 0, 1), structure(list(), .Names = character(0)),
list(name = c("1", "2", "3", "4", "5", "6", "7", "8", "9",
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
"20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
"30", "31", "32"), long = c(-79.260866474359, -80.0214733333333,
-76.7089527272727, -74.780105, -80.2763261538462, -80.46082,
-80.030754125, -80.121487, -82.1419016578947, -81.41021461,
-85.6918532152941, -81.2031545454546, -81.187526, -80.11719,
-80.5063443067816, -82.5245573333333, -78.8618875, -80.883413,
-79.7296606, -76.9488, -77.8201766666667, -76.5490625, -81.5434341458974,
-93.59755, -88.035675, -83.2922209874074, -84.5110066666667,
-79.1122080625, -80.173172, -77.3383016666667, -78.2188216666667,
-77.7654788888889), lat = c(25.7205797179487, 26.85296, 25.53793,
38.33654, 27.1842307692308, 24.948536, 26.99901625, 27.171273,
28.2081715526316, 24.6188354115741, 29.4212288229412, 31.0068890909091,
29.643964, 26.6099285714286, 28.4826687301149, 27.100245,
26.63643, 31.3834996666667, 32.6213106, 34.2073, 24.8982166666667,
24.3104225, 24.6719581623077, 27.90902, 30.0528425, 27.764016172963,
29.706515, 26.97782228125, 25.5103912857143, 34.55239, 26.6567083333333,
26.9487844444444)), list(weight = c(426, 58, 3, 253, 493,
9, 392, 7, 4, 42, 5, 2, 40, 1, 2, 74, 2, 106, 17, 1, 2, 114,
62, 9, 1, 1, 1, 5, 3, 12, 1, 9, 1, 2, 1, 1, 1, 15, 6, 2,
17, 4, 1, 1, 1, 21, 4, 4, 1, 1, 1, 1, 2, 1, 2))), <environment>), class = "igraph")
节点位置:
nodes_pos<-structure(list(x = c(-79.260866474359, -80.0214733333333, -76.7089527272727,
-74.780105, -80.2763261538462, -80.46082, -80.030754125, -80.121487,
-82.1419016578947, -81.41021461, -85.6918532152941, -81.2031545454546,
-81.187526, -80.11719, -80.5063443067816, -82.5245573333333,
-78.8618875, -80.883413, -79.7296606, -76.9488, -77.8201766666667,
-76.5490625, -81.5434341458974, -93.59755, -88.035675, -83.2922209874074,
-84.5110066666667, -79.1122080625, -80.173172, -77.3383016666667,
-78.2188216666667, -77.7654788888889), y = c(25.7205797179487,
26.85296, 25.53793, 38.33654, 27.1842307692308, 24.948536, 26.99901625,
27.171273, 28.2081715526316, 24.6188354115741, 29.4212288229412,
31.0068890909091, 29.643964, 26.6099285714286, 28.4826687301149,
27.100245, 26.63643, 31.3834996666667, 32.6213106, 34.2073, 24.8982166666667,
24.3104225, 24.6719581623077, 27.90902, 30.0528425, 27.764016172963,
29.706515, 26.97782228125, 25.5103912857143, 34.55239, 26.6567083333333,
26.9487844444444)), row.names = 1:32, class = "data.frame")
手动布局:
lay <- create_layout(graph = g, layout = "manual",
node.positions = nodes_pos)
错误信息
Error in layout_fun(graph, circular = circular, ...) : unused argument (node.positions = nodes_pos)
包版本:
- ggraph 2.0.2
- igraph 1.2.4.2
- R 3.6.2
尝试:
g_new <- upgrade_graph(g)
lay <- create_layout(g_new, 'manual',
x = long, y = lat)
ggraph(lay) +
geom_node_point(color = "red") +
geom_polygon(data = map_data("state"), aes(x=long, y=lat, group=group),
color="black", fill="lightblue" )