我想繪製一個網絡可視化,以類似於流程圖。我相當接近用下面的代碼,但我有幾個問題:如何使用固定位置控制igraph繪圖佈局?
- 這是最好的佈局()算法,或我可以手動分配>
- 我怎樣才能使每個節點的位置確定這些節點在劇情中不重疊(就像他們在這裏做的那樣)?
- 我可以將一個節點分配爲「錨點」還是起點?即,我可以讓「C」成爲最頂層還是最左邊的節點?
非常感謝!
library("igraph")
L3 <- LETTERS[1:8]
d <- data.frame(start = sample(L3, 16, replace = T), end = sample(L3, 16, replace = T),
weight = c(20,40,20,30,50,60,20,30,20,40,20,30,50,60,20,30))
g <- graph.data.frame(d, directed = T)
V(g)$name
E(g)$weight
ideg <- degree(g, mode = "in", loops = F)
col=rainbow(12) # For edge colors
plot.igraph(g,
vertex.label = V(g)$name, vertex.label.color = "gray20",
vertex.size = ideg*25 + 40, vertex.size2 = 30,
vertex.color = "gray90", vertex.frame.color = "gray20",
vertex.shape = "rectangle",
edge.arrow.size=0.5, edge.color=col, edge.width = E(g)$weight/10,
edge.curved = T,
layout = layout.reingold.tilford)
感謝您的提示!像這樣把位置放在一起:l2 < - as.matrix(data.frame(c(0,6,12,12,12,24,24,24),c(0,.5,.5 ,0,-1,1,-1,。25))) – 2011-03-20 04:51:13
2年後,這個答案對我有幫助:-) – 2013-06-30 14:26:00
Sacha,當我應用你的代碼時,我得到ncol(x)中的錯誤:找不到對象'L'。在plot(g,layout = gridLayout(L))這一行中,可能有一個我無法理解的問題。 – 2016-10-26 13:42:50