【问题标题】:Vertex Labels Not appearing in iGraph Plot顶点标签未出现在 iGraph 图中
【发布时间】:2022-11-11 01:46:40
【问题描述】:

我正在 iGraph 中绘制一个二分网络。我用来创建图形的 csv 是一个边缘列表,格式如下

V1 V2
node1 node3
node4 node7
node1. node4.

从那里我习惯了以下代码:

g <- graph.data.frame(df, directed=FALSE)

bipartite_mapping(g)
V(g)$type <- bipartite_mapping(g)$type

plot(g)

plot(g, vertex.label.cex = 0.8, vertex.label.color = "black")

V(g)$color <- ifelse(V(g)$type, "lightblue", "salmon")
V(g)$shape <- ifelse(V(g)$type, "circle", "square")
E(g)$color <- "lightgray"

plot(g, vertex.label.cex = 0.8, vertex.label.color = "black")

但是,无论我如何更改颜色标签或其他顶点属性,我都无法让顶点标签(node1、node2 等)显示在图中。

我错过了什么?

非常感谢您的帮助!让自己发疯,我敢肯定这很简单,但我在网上找不到答案。

【问题讨论】:

    标签: r igraph


    【解决方案1】:

    我试过这个:

    g <- make_graph(c("node1", "node3", "node4", "node7", "node1", "node4"), directed = FALSE)
    g
    V(g)$type <- bipartite_mapping(g)$type
    V(g)$type
    
    plot(g, layout=layout_as_bipartite, vertex.label.cex = 0.8, vertex.label.color = "red")
    
    V(g)$color <- ifelse(V(g)$type, "lightblue", "salmon")
    V(g)$shape <- ifelse(V(g)$type, "circle", "square")
    E(g)$color <- "lightgray"
    
    plot(g, layout=layout_as_bipartite)
    

    结果是:

    IGRAPH fea8680 UN-- 4 3 -- 
    + attr: name (v/c)
    + edges from fea8680 (vertex names):
    [1] node1--node3 node4--node7 node1--node4
    
    [1] FALSE  TRUE  TRUE FALSE
    

    对我来说,它完美无缺。

    【讨论】:

      猜你喜欢
      • 2017-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多