2013-01-11 61 views
0

我有這樣的數據幀:表示頂點標籤內部頂點僅

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) 

我想在verexes中顯示頂點標籤,而不增加頂點的大小。任何想法我可以做到這一點?

回答

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) 
+0

這兩個選項都不起作用。由於cex僅更改字體大小。我希望能夠在某些角色之後做一個新的行。 – user1471980

+0

@ user1471980爲什麼不提這個在你的問題?我怎麼會猜到它? – agstudy

+0

@ user1471980我仍在尋找更多細節,爲什麼這不起作用。我測試了2個選項,對我來說他們回答了這個問題。 – agstudy

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);