简体   繁体   English

使用特征向量中心性仅显示特定标签(R中的igraph)

[英]Display only specific labels, using eigenvector centrality (igraph in R)

I am using version 0.99.879 and version 1.0.1. 我正在使用版本0.99.879和版本1.0.1。

My question is rather similar to Show only specific labels on network graph using igraph in R . 我的问题与使用R中的igraph仅在网络图上显示特定标签非常相似。 I have posted my follow-up question on this as a comment there, but was asked to open a new question. 我在此处发表了我的后续问题作为评论,但被要求打开一个新问题。

I also want to display only specific vertex labels and this works fine if you use the or centrality function. 我也只想显示特定的顶点标签,如果您使用 功能,则可以正常工作。 However, I tried it with or centrality and it shows the following error 但是,我尝试使用中心性进行了尝试,结果显示以下错误

Error in ifelse(evcent(g) > 0.1, V(g)$name, NA) : (list) object cannot be coerced to type 'double' ifelse(evcent(g)> 0.1,V(g)$ name,NA)中的错误:(列表)对象不能被强制键入“ double”


Here is the code: 这是代码:

#random graph
library(igraph)

g <- graph( c("John", "Jim", "Jim", "Jack", "Jim", "Jack", "Brian", "John", "John", "Janis", "Janis", "Jennifer", "Justin", "John"), 
                   isolates=c("Jesse", "Brian") )
# works perfectly fine
par(mfrow=c(1,2), mar=c(0,0,1,0))
plot(g, vertex.size=9,
     vertex.label = ifelse(betweenness(g) > 0, V(g)$name, NA),
     edge.arrow.size=.5)
plot(g, vertex.size=9,
     vertex.label = ifelse(degree(g) > 0, V(g)$name, NA),
     edge.arrow.size=.5)
#does not work
plot(g, vertex.size=9,
     vertex.label = ifelse(evcent(g) > 0.01, V(g)$name, NA),
     edge.arrow.size=.5)
# I also tried this with no success
eig <- evcent(g)
par(mfrow=c(1,1), mar=c(0,0,1,0))
plot(g, vertex.size=9,
     vertex.label = ifelse(eig$vector > 0.1, V(g)$name, NA),
     edge.arrow.size=.5)


How can this be fixed. 如何解决此问题。 What exactly does this mean: 这到底是什么意思:

'type double' 'type double'

Thanks in advance for any help! 在此先感谢您的帮助!

Take a look at the help page ?evcent . 查看帮助页面?evcent It says: 它说:

Value

A named list with components: ... 具有组件的命名列表:...

You need to use 您需要使用

ifelse(evcent(g)$vector > 0.01,

and similarly, use hub_cent$vector 同样,使用hub_cent$vector

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM