rplotcircoscirclize

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

Solution

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

    enter image description here