2016-09-18 11 views
3

visNetworkのオプション(visLayout、visOptions、visPhysicsなど)を調整して、マインドマップに似たネットワークビジュアリゼーションを取得できますか?visNetwork Rパッケージ(vis.js javascriptライブラリを使用したネットワークの視覚化)を使用したマインドマップのようなレイアウト

私はこのような何か入手したい: Produced using Mindomo

そして、ここでは、同じデータを描画するvisNetworkを使用してRに私の再現性の例です:

nodes <- structure(list(id = 1:22, label = structure(c(14L, 20L, 19L, 
                 16L, 12L, 18L, 2L, 17L, 22L, 8L, 13L, 3L, 4L, 5L, 6L, 7L, 21L, 
                 15L, 9L, 1L, 10L, 11L), .Label = c("A seemengly impossible mission\n", 
                         "Another \n", "Detail 1\n", "Detail 2\n", "Detail 3\n", "Detail 4\n", 
                         "Detail 5\n", "Do you know where is Dover?\n", "Dover Castle\n", 
                         "Finally, I'm the fifth\n", "I'm alone", "I'm relatively short\n", 
                         "Let's say there is a third one\n", "Main topic\n", "Operation Dynamo\n", 
                         "or, I'm even longer and perhaps I need some more space\n", "Running out of imagination\n", 
                         "Shorter\n", "Some longer text goes here\n", "Thing 1\n", "Thing number 4\n", 
                         "What can happen?\n"), class = "factor"), shape = structure(c(1L, 
                                        1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                        1L, 1L, 1L, 1L, 1L), class = "factor", .Label = "box")), .Names = c("id", 
                                                        "label", "shape"), row.names = c(NA, -22L), class = "data.frame") 

edges <- structure(list(from = c(1L, 2L, 2L, 2L, 2L, 1L, 7L, 7L, 7L, 1L, 
           11L, 11L, 11L, 11L, 11L, 1L, 17L, 17L, 17L, 1L, 21L), to = 2:22, 
         arrows = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
              1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "to", class = "factor")), .Names = c("from", 
                                      "to", "arrows"), row.names = c(NA, 21L), class = "data.frame") 
library(visNetwork) 
visNetwork(nodes, edges) %>% 
    visOptions(highlightNearest = TRUE, nodesIdSelection = TRUE) %>% 
    visLayout(randomSeed = 1) 

このコードは、この可視化を生成します。

enter image description here

だから、最初の人物ははるかにクリーンで読みやすく、使いやすいことが分かります。 visNetworkパラメータ(vis.jsパラメータ)を微調整して、結果をここの最初の図と比較的似ていますか?

基本的には、メイントピックを中心にしていて、メイントピックの周りに放射状に配置された次のレベルのトピックと、互いに関連したレベル(リストの一種)です。

+1

[networkD3](https://christophergandrud.github.io/networkD3/)パッケージから –

答えて

4

座標を渡してノードdata.frameに渡し、物理を無効にすることができます。

あなたがしたいノードを配置し、光沢のあるアプリを使用して座標を取り戻す、その後、例えばこのように、あなたのネットワークでこれを使用することができます。

mynetwork <- visNetwork(nodes, edges) %>% 
    visOptions(highlightNearest = TRUE, nodesIdSelection = TRUE) %>% 
    visLayout(randomSeed = 1) %>% 
    visPhysics(enabled = FALSE) # disable physics to move nodes 

require(shiny) 
server <- function(input, output) { 
    output$network <- renderVisNetwork({ 
    mynetwork 
    }) 

    vals <- reactiveValues(coords=NULL) 

    output$view <- renderPrint({ 
    write.table(vals$coords, file = "save_coordinates.csv", sep = ";") 
    vals$coords 
    }) 

    observe({ 
    input$getcoord 
    visNetworkProxy("network") %>% visGetPositions() 
    vals$coords <- if (!is.null(input$network_positions)) 
     do.call(rbind, input$network_positions) 
    }) 
} 

ui <- fluidPage(
    visNetworkOutput("network", height = "800px"), 
    actionButton("getcoord", "View & Save Coordinates"), 
    verbatimTextOutput("view") 
) 

shinyApp(ui = ui, server = server) 


# and after, put coordinnates into nodes data.frame and use visNodes(fixed = TRUE) 
# if you want 

coord <- read.csv("save_coordinates.csv", sep = ";") 
nodes <- cbind(nodes, coord) 

visNetwork(nodes, edges) %>% 
    visNodes(fixed = T) %>% 
    visOptions(highlightNearest = TRUE, nodesIdSelection = TRUE) %>% 
    visLayout(randomSeed = 1) %>% 
    visPhysics(enabled = FALSE) 

あなたはまたlevelvisHierarchicalLayoutと遊ぶことができます。

nodes <- data.frame(id = 1:9, level = c(1,1,2,3,3, 4, 4, 4, 4)) 
edges <- data.frame(from = c(3, 3, 3, 3, 4, 4, 5, 5), 
        to = c(1, 2, 4, 5, 6, 7, 8, 9)) 


visNetwork(nodes, edges) %>% 
    visHierarchicalLayout(direction = "LR") 
+0

おかげで 'radialNetwork()'を見ているかもしれない!これは素晴らしいソリューションです。しかし、(それがなければならない)それは1タイマーと1つの特定のネットワークのための素晴らしい解決策です。私は実際には、ネットワークを問わず、心地よい形でノードを巧みに配置する「自動」なものを探していました。 @StevenBeaupréの示唆したように、私が見つけた最も近いのは 'networkD3'パッケージの' radialNetwork() 'ですが、すべてのネットワークを半径方向に並べるようなものです。私は、第一レベルの放射状配置、第二レベルの垂直配置 – elikesprogramming

+0

'level'と' visHierarchicalLayout'でこれを行うことができます。私の答えに例を挙げてください。 – bthieurmel

関連する問題