2014-06-20 8 views
2

두 그래프의 공유 노드를 같은 위치에 플로팅하는 방법이 있습니까? 예 : 두 개의 그래프동일한 위치에 정점 플롯

g1 = graph.ring(5) 
V(g1)$name=c('node1','node2','node3','node4','node5') 
g1 = g1 - V(g1)[1] 


g2 = graph.ring(5) 
V(g2)$name=c('node1','node2','node3','node4','node5') 
g2 = g2 - V(g2)[2] 

g1과 g2에는 3 개의 노드가 있습니다. 차이점을 쉽게 비교할 수 있도록 같은 위치의 같은 노드로 어떻게 그릴 수 있습니까?

par(mfrow=c(1,2)) 
plot(g1, vertex.label=V(g1)$name) 
plot(g2, vertex.label=V(g2)$name) 
+0

가장자리 노드에는 1-4라는 노드가 있습니다. 아마도'graph.ring'이이 예제에서 사용하는 것이 최선의 방법이 아니겠습니까? – MrFlick

+0

[This] (http://stackoverflow.com/questions/24301992/how-to-fix-nodes-when-plotting-a-subset-over-a-complete-network-using-igraph-r#comment37559179_24301992) 도움? – user20650

+0

@MrFlick 새로운 것을 시도하십시오 – yliueagle

답변

3

의견에 링크 된 질문의 코드를 사용하면 한 그래프에서 위치를 가져 와서 다른 그래프에서 사용할 수 있습니다. 옆에

# Graphs - tweaked the node names 
g1 = graph.ring(5) 
V(g1)$name=letters[1:5] 
g1 = g1 - V(g1)[1] 

g2 = graph.ring(5) 
V(g2)$name=letters[2:6] 
g2 = g2 - V(g2)[2] 


# graph layouts 
# g1 
set.seed(1) 
layg1 <- layout.fruchterman.reingold(g1) 

# g2 
set.seed(2) 
layg2 <- layout.fruchterman.reingold(g2) 
# overwrite coords for shared nodes 
layg2[which(V(g2)$name %in% V(g1)$name), ] <- 
             layg1[which(V(g1)$name %in% V(g2)$name),] 

xlim <- range(c(layg1[,1], layg2[,1])) 
ylim <- range(c(layg1[,2], layg2[,2])) 

플롯 측

par(mfrow=c(1,2)) 
plot(g1 , vertex.size=50, layout=layg1, xlim=xlim, ylim=ylim, rescale=FALSE) 
plot(g2 , vertex.size=50, layout=layg2, xlim=xlim, ylim=ylim, rescale=FALSE) 

enter image description here

또는 다른 색상 노드 중 하나 개 세트와 내가 그들을 플롯하면, 그들은 보를 모십니다

V(g2)$color <- "red" 
E(g2)$color <- "red" 

plot(g1 , vertex.size=50, layout=layg1, xlim=xlim, ylim=ylim, rescale=FALSE) 
plot(g2 , vertex.size=30, layout=layg2, xlim=xlim, ylim=ylim, rescale=FALSE, add=T) 

enter image description here

관련 문제