简体   繁体   English

R Circlize,带空扇区的和弦图

[英]R Circlize, Chord graph with empty sectors

I am trying to create a chord graph using the circlize package in R. I would like to include sectors for which there is no outflow (no links emanating from them). 我正在尝试使用R中的circlize包创建一个和弦图。我想包括没有流出的扇区(没有从它们发出的链接)。 Is there a way to: 有办法:

  1. Force the program to report rows from my data frame, even if there are only zeros in that row. 强制程序报告我的数据框中的行,即使该行中只有零。

  2. Suppress self-loops. 抑制自循环。 (The vignettes calls on you to enter zeros at the diagonal to do this, but then we're back to the first problem.) (小插曲要求你在对角线上输入零来做这个,但后来我们又回到了第一个问题。)

I have attached my code. 我附上了我的代码。

chordDiagram(mat, symmetric = TRUE, keep.diagonal = TRUE, order = union(rownames(mat), colnames(mat)),
             directional = FALSE, annotationTrack = "grid", preAllocateTracks = list(
               list(track.height = 0.05),
               list(track.height = 0.05))
)

Here is some sample data. 这是一些示例数据。

    a.1 a.2 a.3 a.4 a.5 a.6 a.7 a.8 a.9
a.1 1   0   0   0   1   0   0   0   0
a.2 0   1   0   0   0   0   0   1   0
a.3 0   0   1   0   0   0   0   0   0
a.4 0   0   0   1   0   0   0   0   0
a.5 1   0   0   0   1   0   0   0   0
a.6 0   0   0   0   0   1   0   0   1
a.7 0   0   0   0   0   0   1   0   1
a.8 0   1   0   0   0   0   0   1   1
a.9 0   0   0   0   0   1   1   1   1

Since there is no link from that sector, how do you define the width of that sector? 由于该部门没有链接,您如何定义该部门的宽度?

Anyway, you can add an 'empty' sector by assign some value to that vector and draw the link with completely transparent colors. 无论如何,您可以通过为该向量指定一些值并使用完全透明的颜色绘制链接来添加“空”扇区。

> mat = matrix(c(5, 0, 0, 0, 2, 3, 0, 3, 2), 3)
> colnames(mat) = letters[1:3]
> rownames(mat) = letters[1:3]
> mat
  a b c
a 5 0 0
b 0 2 3
c 0 3 2

> col = matrix(rand_color(9), 3)
> col[1, 1] = "#FFFFFF00"
> chordDiagram(mat, col = col)

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM