【问题标题】:Formatting chord diagram based on matrix-input基于矩阵输入格式化和弦图
【发布时间】:2019-01-09 01:51:56
【问题描述】:

现状

在我之前的问题Data frame into a symmetric matrix while keeping all row and column 中,我最终得到了一个对称矩阵,我想将其转换为这样的格式化和弦图:

library(edgebundleR)

# data
x <- structure(c(1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0), 
               .Dim = c(3L,5L), 
               .Dimnames = list(c("a.X", "a.Y", "b.Z"), c("a.A", "a.B", "a.C", "b.D", "b.E")))
x <- as.matrix(x)
x <- rbind(cbind(diag(nrow(x)), x), cbind(t(x), diag(ncol(x))))
colnames(x) <- rownames(x)

# plot
edgebundle(x)

# plot with basic formatting using the arguments of edgebundle()
edgebundle(x,
           tension=1,
           fontsize = 12,
           cutoff = 0, 
           width = 1000,
           padding = 230,
           nodesize = c(5, 30))

问题

但是,类似于Color edges and vertex in chord diagram using edgebundle,我想更进一步并更改线条和节点的颜色(默认情况下和鼠标悬停期间),这在使用 igraph-object 时是可能的,如@987654323 所示@ 和documentation

在阅读了edgebundleRPDF-documentation 之后,我想这不是该软件包功能的一部分,但它也可以...

  • 包括基于组c("a.", "b.") 的分组标签
  • 更改文本的字体
  • 对指向不同组的线条使用不同颜色 已选择类别(如 example 中的输入和输出)
  • 为绘图添加标题,当绘图旋转时保持原位

我的问题

  1. 是否可以在使用 矩阵而不是 igraph 对象,优先使用颜色代码 (RGB,十六进制),如果是,如何?
  2. 尽管未包含在基本功能中,但是否有 从上面进行高级格式化的方法? (当然,不必在很大程度上重写或扩展包)

感谢您的建议!

【问题讨论】:

    标签: r matrix plot chord-diagram


    【解决方案1】:

    与此同时,我想出了一个方法来改变整个情节的颜色(包括文本、线条和节点)。我想在这里分享它,以便为志同道合的人节省几个小时的研究时间。

    1。更改和弦图的颜色

    它通过将矩阵转换为 igraph 对象并通过顶点V() 函数设置颜色来工作。颜色可以按组设置,每个顶点使用循环设置,或者在仅使用一种颜色时作为一个整体设置。

    library(igraph)   
    
    # transform into igraph-object
    y <- graph_from_adjacency_matrix(as.matrix(x, "adjacency"), mode = "undirected")
    
    # setting colors
    
    # Per group
    V(y)[which(substring(colnames(x),0,1) %in% "a")]$color <- "green"
    V(y)[which(substring(colnames(x),0,1) %in% "b")]$color <- "red"
    edgebundle(y)
    
    # vertex per vertex
    V(y)$color <- c("green", "red") 
    edgebundle(y)
    
    # as a whole
    V(y)$color <- "#a98561" # hex-codes are supported
    edgebundle(y)
    

    2。高级格式化

    毕竟,igraph 带有定义标题y$main 的函数,通过使用E() 函数E(y)$color 更改线条(即边缘)的颜色,更改标签的字体V(y)$label.family 和其他用于更好格式化的工具(请参阅:manual)。不幸的是,edgebundleR 包不支持这些东西。它们在使用时没有任何作用。下面,我提供了一个简短的示例来感受这些设置,显示edgebundle()plot.igraph() 之间的差异。

    # settings
    y$main <- "Title"
    E(y)$color <- "red"
    V(y)$label.family <- "Arial"
    
    # see plots
    plot.igraph(y)
    edgebundle(y)
    

    如果不扩展包,似乎无法在鼠标悬停期间更改线条的颜色,即边缘。 edgebundle() 的默认设置为标准线指向蓝色,鼠标悬停时指向红色。一旦指定,这些值将被替换为相同的颜色。目前没有为标准线和鼠标悬停定义不同颜色的选项。

    也无法将分组标签添加到文本组。

    前景

    如果有人能够解决这些问题,或者如果 edgebundleR 收到包含新功能的更新,欢迎您扩展此答案。

    【讨论】:

      猜你喜欢
      • 2020-08-15
      • 2018-05-07
      • 2020-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多