仅在顶点内显示顶点标签

时间:2013-01-11 14:26:05

标签: r igraph

我有这个数据框:

dput(DF2)

structure(list(Receiver = structure(c(4L, 3L, 2L, 1L), .Label = c("Australia", 
"United Arab Emirates", "United Kingdom", "United States of America"
), class = "factor"), Sender = structure(c(1L, 1L, 1L, 1L), .Label = "United States of America", class = "factor")), .Names = c("Receiver", 
"Sender"), row.names = c(NA, -4L), class = "data.frame")

我想绘画和igraph这样:

library(igraph)
g<-graph.data.frame(df2)
plot(g, layout = layout.kamada.kawai,  vertex.label = V(g)$name,  
     vertex.label.color= "red",  edge.arrow.size=0.8,  
      edge.curved=T, edge.label.color="white",                              
      edge.label.cex=0.8,vertex.shape="circle",edge.color="pink",
      vertex.color="lightblue", asp=0, margin=0)

我想在verex中显示顶点标签,而不增加顶点的大小。我有什么想法可以做到这一点吗?

2 个答案:

答案 0 :(得分:2)

你可以在调用图之前做这样的事情:

  V(g)$label.cex <- 0.5

但为什么不使用名称的快捷方式?

 V(g)$name<-c('USA','UK','UAE','Aus')

enter image description here

dat <- structure(list(Receiver = structure(c(4L, 3L, 2L, 1L), .Label = c("Australia", 
                                                                  "United Arab \nEmirates", "United \nKingdom", "United \nStates of \nAmerica"
), class = "factor"), Sender = structure(c(1L, 1L, 1L, 1L), .Label = "United \nStates of \nAmerica", class = "factor")), .Names = c("Receiver", 
                                                                                                                                "Sender"), row.names = c(NA, -4L), class = "data.frame")


library(igraph)
g<-graph.data.frame(dat)
V(g)$label.cex <- 0.6
plot(g, layout = layout.kamada.kawai,  vertex.label = V(g)$name,  
     vertex.label.color= "red",  edge.arrow.size=0.8,  
     edge.curved=T, edge.label.color="white",                              
     edge.label.cex=0.8,vertex.shape="circle",edge.color="pink",
     vertex.color="lightblue", asp=0, margin=0)

答案 1 :(得分:0)

以下内容可能有所帮助。

# size the network nodes based on their centrality
deg = igraph::degree(graph = g, v = V(g), mode = "all", loops = TRUE, normalized = FALSE);
igraph::V(g)$size = deg*3;

# set the label size based on the node size
igraph::V(g)$label.cex = igraph::V(g)$size/max(igraph::V(g)$size);