[英]How to plot directed acyclic lattice graph in R
我需要繪制尺寸為mxn的有向無環格子圖,類似於此圖片,但是輪廓上沒有邊緣,角落上沒有頂點:
這可能與graph.lattice
函數有關嗎? 如果是,如何設置此類頂點的標簽(即(x,y)格式,而不僅僅是整數)並刪除提到的邊線和頂點? 此外,是否可以在不使用tkplot函數並旋轉的情況下將圖形繪制在這樣的位置(如在圖片中)?
我不確定“輪廓上沒有邊緣”是什么意思,但是這里有幾點:
?igraph.plotting
以獲取繪圖參數的完整列表。 vertex.frame.color
設置為與vertex.color
相同的值。 layout.grid
,請參閱?layout.grid
。 vertex.label
設置標簽。 layout.grid
計算的坐標作為頂點屬性,然后從圖形中刪除這些頂點。 這樣的事情可能會起作用:
g <- graph.lattice( c(5,5) )
lay <- layout.grid(g)
V(g)$x <- lay[,1]
V(g)$y <- lay[,2]
V(g)$color <- V(g)$frame.color <- "darkolivegreen"
V(g)$label.color <- "lightgrey"
V(g)$label <- paste(V(g)$x+1, V(g)$y+1, sep=",")
要刪除邊緣,可以根據頂點的坐標選擇它們:
torem <- c(E(g)[ V(g)[x==0] %--% V(g)[x==0] ],
E(g)[ V(g)[y==0] %--% V(g)[y==0] ],
E(g)[ V(g)[x==4] %--% V(g)[x==4] ],
E(g)[ V(g)[y==4] %--% V(g)[y==4] ])
g2 <- delete.edges(g, torem)
然后刪除頂點並繪制:
g3 <- delete.vertices(g2, V(g2)[ x %in% c(0,4) & y %in% c(0,4) ])
plot(g3, layout=cbind(V(g3)$x, V(g3)$y))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.