2016-07-20 2 views
0
I 원형 배치 형식 visNetwork를 생성하도록 다음 코드를 사용하고

에서 원으로 igraph 시각화(아래 첨부 된 이미지) 내외 R

I가되도록하는 방식으로 레이아웃을 변경할
visNetwork(data$nodes,data$edges) %>% visIgraphLayout(layout="layout_in_circle") 

, 내부 원 안에는 녹색 노드가, 외부 원에는 파란색 노드가 있습니다. 이를 달성하는 방법을 알려주십시오.

미리 감사드립니다. Image Link

답변

2

igraph에서 레이아웃을 만드는 것도 한 가지 방법입니다. 마지막에 visNetwork로 다시 공급할 수 있습니다. 당신이 안쪽 원이 바깥 쪽을 연결하기를 원한다면 나는 확신하지 못했습니다. 두 옵션 모두 코딩됩니다.

노드 매트릭스를 서브 세트하여 만든 녹색 노드 nodes1과 파란색 노드 nodes2을 호출하십시오.

# edges within nodes1 
edges1 <- edges[edges$from%in%nodes1$id & edges$to%in%nodes1$id, ] 
# edges within nodes2 
edges2 <- edges[edges$from%in%nodes2$id & edges$to%in%nodes2$id, ] 
# edges within nodes1 or 2 = all edges if nodes1, 2 account for all nodes 
edges12 <-edges[edges$from%in%c(nodes2$id,nodes1$id) & 
    edges$to%in%c(nodes2$id,nodes1$id) , ] 

igraph1 <- graph.data.frame(edges1, directed=F, vertices=nodes1) 
igraph2 <- graph.data.frame(edges2, directed=F, vertices=nodes2) 

# inner circle doesn't connect to outer: 
igraph12a <- graph.data.frame(rbind(edges1, edges2), directed = F, 
    vertices = rbind(nodes1, nodes2)) 

# inner circle can connect to outer: 
igraph12b <- graph.data.frame(edges12, directed = F, vertices = 
    rbind(nodes1, nodes2)) 

l1 = layout.circle(igraph1) 
l2 = layout.circle(igraph2) 
l12 = rbind(l1, l2 * 0.5) # 0.5 term scales the inner circle size 

# plot both circles 
plot.igraph(igraph1, layout = l1, rescale = F) 
plot.igraph(igraph2, layout = l2*.5, add = T, rescale = F) 

# plot both circles at once 
plot.igraph(igraph12a, layout = l12, rescale = F) 

# plot both circles with possible connections between them 
plot.igraph(igraph12b, layout = l12, rescale = F) 

그런 다음 visNetwork에서 선호한다면 그렇게 할 수 있습니다. layoutMatrix 기능과 layout.norm가 최근에 추가하기 때문에 당신이 visNetwork의 업데이트 된 버전이 있는지 확인 : 물론

visNetwork(nodes = rbind(nodes1, nodes2), edges = edges12) %>% 
    visIgraphLayout(layout="layout.norm", layoutMatrix = l12) 

, 당신은 다음의 모든 노드 색상을 추가 할 수 있습니다.

+0

감사합니다. Jac. 그것은 당신이 제공 한 코드로 작동했습니다. – hr02

+0

@ hr02 jac 님의 질문에 대한 답변이 성공적으로 접수되었습니다. [누군가 내 질문에 대답하면 어떻게해야합니까?] (https://stackoverflow.com/help/someone-answers)를 참조하십시오. – G5W