小编tot*_*drm的帖子

使用ggnet2在R中按度数着色

我一直试图用图表绘制图表ggnet2.为此,我使用以下代码:

library(igraph)
lapply(c("sna", "intergraph", "GGally", "igraph", "network"), require, character.only=T)
data <- read.table('CA-CondMat.txt',sep="\t",header=TRUE)
g = graph.data.frame(data, directed = TRUE)
N = vcount(g)
E = ecount(g)
perc = 0.1
d.g = degree(g,mode='all')/N
new_nodes = sample.int(N,ceiling(perc*N),replace=FALSE,prob =d.g)
new_g = subgraph(g,new_nodes)
dg = degree(g,mode='all')
prob = dg/sum(dg)
png('example_plot2.png')
ggnet2(new_g, size = "degree", node.color = "steelblue", size.cut = 4,
                                          edge.size = 1, edge.color="grey" )
dev.off()
Run Code Online (Sandbox Code Playgroud)

我得到一个完全蓝色的图表.

我正在使用这个包igraph.

我想要绘制的是一个图表,节点的颜色基于它们的程度,如下所示: 在此输入图像描述

链接到该文件:https:
//snap.stanford.edu/data/ca-CondMat.html

编辑:

完整示例添加

r igraph ggplot2 graph-visualization ggally

3
推荐指数
1
解决办法
766
查看次数

标签 统计

ggally ×1

ggplot2 ×1

graph-visualization ×1

igraph ×1

r ×1