我正在使用ggnet2绘制网络。我的网络的权重范围从-1到1.我试图找到一种解决方法,以某种方式着色(或行输入)那些负数的值,这样我就可以将它们与那些积极的值区分开来。
以下是示例数据:
n <- data.frame(event1 = c(-0.2,0.8,0.4),
event2 = c(0.34,-0.17,0.3),
event3 = c(0.2,0.1,-0.73),
row.names = letters[1:3])
net <- network(net,
matrix.type = "bipartite",
ignore.eval = FALSE,
names.eval = "weights")
然后当我去绘制它时:
ggnet2(net,label = TRUE, edge.size = "weights")
由于负值,我收到错误:ggnet2中的错误(bip,label = TRUE,edge.size =“weights”): 不正确的edge.size值
有没有人有关于如何以某种方式突出这些优势的想法?我想我可以在每个末尾添加另一个sig数字,就像一个“1”,所以我可以专门用掉那些值,但我无法弄清楚如何设置代码来为特定边缘着色或更改特定边缘的线条类型。提前谢谢!
答案 0 :(得分:0)
您可以为负边和正边值指定颜色。例如:
n <- data.frame(event1 = c(-0.2,0.8,0.4,0),
event2 = c(0.34,-0.17,0.3,0),
event3 = c(0.2,0.1,-0.73,0),
row.names = letters[1:4])
net <- network(n,
matrix.type = "bipartite",
ignore.eval = FALSE,
names.eval = "weights")
col = c("actor" = "grey", "event" = "gold")
set.edge.attribute(net, "color", ifelse(net %e% "weights" > 0, "green", "red"))
ggnet2(net, color = "mode", palette = col, label = TRUE, edge.color = "color")
有关更多信息和示例,请查看此处: ggnet2: network visualization with ggplot2