本文介绍了R Circlize,带有空扇区的和弦图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用R中的circlize包创建一个和弦图.我想包括没有流出的扇区(没有从它们发出的链接).有没有办法:

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). Is there a way to:

  1. 强制该程序报告我数据框中的行,即使该行中只有零.

  1. Force the program to report rows from my data frame, even if there are only zeros in that row.

抑制自循环. (小插图呼吁您在对角线输入零,但这要回到第一个问题.)

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.)

我已附上我的代码.

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))
)

这是一些示例数据.

    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)

这篇关于R Circlize,带有空扇区的和弦图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 04:33