【问题标题】:How to input tabular data and output circular packing plot?如何输入表格数据并输出圆形包装图?
【发布时间】:2019-11-29 15:10:02
【问题描述】:

我真的很困惑我应该使用什么输入,我无法从示例数据集中解决它。

我有一个这样的数据集:

node1   node2   edge_score
x1      x2      0.1
x1      x3      0.2
x8      x4      0.1
x4      x5      0.4
x6      x7      0.5

(在现实生活中,分数表示两个节点的相似程度)。

我想在these 圆形包装图中绘制这些。

但与他们用作示例的耀斑数据集相比,我无法弄清楚如何输入我的数据(因为我猜这里我可以输入两个顶点,节点 A 和节点 B?)。

所以输入应该是上面的表格,输出应该是带有三个较小子圆圈的气泡图(一个大圆圈):

One circle has x1, x2 and x3
one circle has x8, x4 and x5
one circle has x6 and x7

如果可以将边缘分数合并到圆圈的大小中,那会很棒,但我不知道边缘是如何包含在这个分析中的,但是,它们会被读入示例中吗?或者我猜即使有人可以演示如何更改节点大小,如果我添加另一个具有某些节点大小或其他内容的列。

【问题讨论】:

    标签: r igraph ggraph


    【解决方案1】:

    ggraph 的文档表明“circlepacking”基本上是一个树形图,因此该图应该反映一个层次结构。

    按照定义,您的图表产生三个不相连的组:

    library(tidyverse)
    library(igraph)
    library(ggraph)
    
    df <- read.table(text="node1   node2   edge_score
    x1      x2      0.1
    x1      x3      0.2
    x8      x4      0.1
    x4      x5      0.4
    x6      x7      0.5", header = TRUE, stringsAsFactors = FALSE)
    
    
    g <- graph_from_data_frame(
      df,
      directed = TRUE
    )
    
    ggraph(g, layout = "auto") +
      geom_edge_link() +
      geom_node_text(aes(label = name)) +
      coord_fixed()
    

    如果我稍微修改一下,我会尝试更接近你所要求的情节(不完全接近):

    df <- read.table(text="node1   node2   edge_score
    x1      x2      0.1
    x1      x3      0.2
    x2      x6      0.1
    x2      x7      0.3
    x3      x4      0.1
    x4      x5      0.4
    x4      x8      0.5", header = TRUE, stringsAsFactors = FALSE)
    
    g <- graph_from_data_frame(
      df,
      directed = TRUE
    )
    
    g <- graph_from_data_frame(
      df,
      directed = TRUE
    )
    
    V(g)$r = 1
    
    ggraph(g, layout = "auto") +
      geom_edge_link() +
      geom_node_text(aes(label = name)) +
      coord_fixed()
    
    ggraph(g, layout = "circlepack") +
      geom_edge_link() +
      geom_node_circle() +
      geom_node_text(aes(label = name)) +
      coord_fixed()
    
    

    图形更像“树状”

    而且它的“circlepacks”更好一点

    HTH

    【讨论】:

      猜你喜欢
      • 2020-11-13
      • 1970-01-01
      • 1970-01-01
      • 2021-12-30
      • 1970-01-01
      • 2016-12-04
      • 2010-12-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多