R Circlize, Chord graph with empty sectors

丶灬走出姿态 提交于 2020-01-16 00:58:08

问题


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

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



来源:https://stackoverflow.com/questions/30432224/r-circlize-chord-graph-with-empty-sectors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!