我hvar以下数据集:
structure(c(2L, 6L, 2L, 6L, 7L, 7L, 2L, 7L, 6L, 8L, 8L, 4L, 8L,
2L, 9L, 8L, 7L, 6L, 9L, 1L, 9L, 4L, 9L, 3L, 2L, 10L, 9L, 10L,
8L, 10L, 7L, 6L, 10L, 1L, 2L, 12L, 9L, 8L, 12L, 1L, 11L, 10L,
2L, 44L, 79L, 10L, 8L, 47L, 45L, 51L, 9L, 11L, 74L, 75L, 77L,
69L, 75L, 77L, 78L, 2L, 44L, 44L, 46L, 46L, 8L, 6L, 1L, 1L, 6L,
7L, 1L, 4L, 7L, 8L, 8L, 1L, 4L, 8L, 3L, 8L, 8L, 9L, 9L, 9L, 1L,
9L, 5L, 9L, 3L, 9L, 9L, 9L, 10L, 8L, 10L, 7L, 10L, 10L, 1L, 10L,
10L, 9L, 12L, 12L, 1L, 12L, 12L, 12L, 12L, 7L, 7L, 44L, 44L,
44L, 44L, 44L, 44L, 44L, 44L, 44L, 44L, 7L, 7L, 7L, 7L, 44L,
10L, 9L, 42L, 43L, 46L, 46L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, -1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, -1L, 1L, 1L, 1L, -1L, -1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, -1L), .Dim = c(66L,
3L), .Dimnames = list(NULL, c("from", "to", "impact")))
数据集表明,from 和 to 之间的联系具有正面 (1) 或负面 (-1) 影响。
我想用 ggnet(或 ggplot2)绘制一个网络图来绘制这个图。
到目前为止,我已经完成了以下步骤:
library(network)
library(ggplot2)
library(ggnet)
library(grid)
net <- network(df2[,c(1,2)], directed = FALSE)
ggnet(net, mode = 'kamadakawai', size = 6, alpha = .5, label.nodes=F, segment.alpha = 0.5, color = "black") +
theme(legend.position = "none") +
theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "cm"))
这导致了这个结果:
我想知道如何根据数据集中的影响对边缘进行着色(1 = 绿色,-1 = 红色)。我也想知道为什么有这么多未连接的节点......
有人可以帮我弄这个吗?
非常感谢。