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)
, 당신은 다음의 모든 노드 색상을 추가 할 수 있습니다.
감사합니다. Jac. 그것은 당신이 제공 한 코드로 작동했습니다. – hr02
@ hr02 jac 님의 질문에 대한 답변이 성공적으로 접수되었습니다. [누군가 내 질문에 대답하면 어떻게해야합니까?] (https://stackoverflow.com/help/someone-answers)를 참조하십시오. – G5W