使用 igraph 绘制网络时出现巨大的箭头

Gigantic arrow heads when plotting network with igraph

编辑 我试图弄清楚我的代码出了什么问题,然后我开始绘制简单的图表以查看箭头在较小的图表上的外观。我厌倦了以下命令:

 g2 <- graph( edges=c(1,2, 2,3, 3, 1), n=10 ) 
 plot(g2)   

这是我的图表:。因此,我认为问题不在于我的代码,而在于 igraph 或 R。我重新安装了 igraph 和 R,但它没有解决问题。是否有可能导致这种情况的包冲突?这是我安装的一些软件包:

 [1] "base"         "boot"         "class"        "cluster"     
 [5] "codetools"    "colorspace"   "compiler"     "datasets"    
 [9] "dichromat"    "digest"       "doParallel"   "foreach"     
[13] "foreign"      "graphics"     "grDevices"    "grid"        
[17] "gridBase"     "gtable"       "igraph"       "irlba"       
[21] "iterators"    "KernSmooth"   "labeling"     "lattice"     
[25] "lazyeval"     "magrittr"     "MASS"         "Matrix"      
[29] "methods"      "mgcv"         "munsell"      "nlme"        
[33] "NMF"          "nnet"         "parallel"     "pkgmaker"    
[37] "plyr"         "RColorBrewer" "Rcpp"         "registry"    
[41] "reshape2"     "rngtools"     "rpart"        "scales"      
[45] "spatial"      "splines"      "stats"        "stats4"      
[49] "stringi"      "stringr"      "survival"     "tcltk"       
[53] "tibble"       "tools"        "utils"        "xtable"    

我正在尝试生成网络图,出于某种原因,我的箭头看起来像小矩形而不是通常的三角形箭头。

这是我用于绘图的代码:

toy.edges <- na.omit(read.csv("Data/Edge_list-toy.csv", header = TRUE, colClasses = "numeric", na.strings = c("NA", "", "#N/A")))
toy.nodes <- na.omit(read.csv("Data/NodesDataF-toy.csv", header = TRUE, na.strings = c("NA", "", "#N/A")))
toy.graph <- graph_from_data_frame(toy.edges, directed = TRUE, vertices = toy.nodes)

V(toy.graph)$color <- "magenta" 
V(toy.graph)$shape <- "sphere"
V(toy.graph)$size <- 3*15^(ifelse(is.na(V(toy.graph)$node.size), 0.001, 
V(toy.graph)$node.size))
plot(toy.graph, layout = layout.fruchterman.reingold(toy.graph),
     vertex.label=NA, edge.width=E(toy.graph)$weight, 
     edge.arrow.size=0.005, edge.arrow.width=0.0000001)

这是一个示例图:

当我为 edge.arrow.size 取稍大的值时看起来更糟 和 edge.arrow.width

我的代码有什么问题?它与R的版本有关吗?我以前用非常相似的命令做了很多图,我从来没有遇到过问题。

这里是 nodes info and edge list.

的文件

看来问题出在 R 如何在我的计算机上显示图形。当我没有直接在控制台中绘制图形,而是将其保存到文件中时,一切看起来都很好。这是我正在使用的代码,以防其他人遇到类似问题:

png("my-plot.png", width=1200, height=1200)
par(mar=c(0,0,0,0))
plot(mat_gr, layout = layout.auto(mat_gr), vertex.label=NA,   
     edge.width=E(mat_gr)$weight)
dev.off()

我意识到它并没有解决显示巨大箭头的问题,但至少它允许生成保存可用的图。

使用 plot.igraph() 而不是简单地 plot() 在这里可能会有帮助。

参数edge.arrow.size可能有助于减小箭头大小。通过此 link 可获得有关绘图函数文档的更多信息。基本上,我们可以通过在参数前添加 vertex/edge 来使用所有列出的参数。

plot(g2, edge.arrow.size = 0.1)