简体   繁体   中英

delete igraph vertices but retain all edges in R

Is there a way to delete (or selectively display) vertices but retain edges in an igraph plot? For example, in the code below, we delete vertices but that deletes edges between them. My goal is to highlight a specific node but keep all edges.

g <- make_ring(10) %>%
  set_vertex_attr("name", value = LETTERS[1:10])
g
V(g)

g2 <- delete_vertices(g, c(1,5)) %>%
  delete_vertices("B")
g2
V(g2)

If you delete the vertices, the edges no longer make any sense. However, if all you want is to not display the vertices, you can just use vertex.size=0 .

plot(g, vertex.size=0)

节点未显示。

If you do not want to even see the node names, add vertex.label=NA

You can show just one node by making a vector of vertex sizes and labels

VS = rep(0, vcount(g))
VS[2] = 14
VL = rep(NA, vcount(g))
VL[2] = V(g)$name[2]

VFC = rep(NA, vcount(g))
VFC[2] = "black"
VC = rep(NA, vcount(g))
VC[2] = 1

plot(g, vertex.size=VS, vertex.label=VL, vertex.color=VC,
    vertex.frame.color=VFC)

只是一个节点

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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