【发布时间】:2021-07-31 01:22:42
【问题描述】:
# Erdos
par(mfrow=c(1,2))
g <- erdos.renyi.game(100, 1/100)
V(g)$size<-seq(0.05,5,0.05)
betweenness(g)
# Draw nodes and save positions
locs <- layout.fruchterman.reingold(g)
plot(g,
layout=locs,
vertex.label=NA,
main="Original",
vertex.color=degree(g))
g
vertex.color=degree(g)
没用。谁能告诉我如何按“度数”为顶点着色? 红色(高值)到蓝色(低值)将是完美的。
谢谢!
【问题讨论】:
-
你的意思是它不起作用,因为你的情节确实有不同程度的颜色?
-
如果你想拥有从蓝色到红色的颜色,只需定义你自己的配色方案:例如。
d=degree(g); cols=setNames(colorRampPalette(c("blue", "red"))(length(unique(d))), unique(d))然后使用vertex.color=cols[degree(g)]设置颜色。但是,这里的颜色范围可能不够:plot(1:6, col=cols, pch=16, cex=3),但只需更改cols向量以适合。 -
这已经有所帮助。但看起来最大值以透明背景显示。其他一切都很好地从红色缩放到蓝色..
-
是的,对不起...使用
cols=setNames(colorRampPalette(c("blue", "red"))(length(unique(d))), sort(unique(d)))从零到上限排序,度数到字符vertex.color=cols[as.character(degree(g))] -
给出“seq.int(0, 1, length.out = n) 中的错误:'length.out' 必须是非负数另外:警告消息:在 .approxfun(x , y, v, method, yleft, yright, f) :“强制引入的 NAs”。cols[as.character(degree(g))] 看起来像:
NA NA NA .. .
标签: r attributes igraph