Search code examples
rcircoscirclize

R: Changing colors on chord diagram in R


Basic question.

I have an input table like this:

    1   2   3   4   5   6   7
1   0   0   1098    11  137 105 338
2   0   0   351 0   1   0   0
3   0   0   0   132 215 91  191
4   0   0   0   0   6   10  19
5   0   0   0   0   0   37  95
6   0   0   0   0   0   0   146
7   0   0   0   0   0   0   0

I wrote this code in R:

 library(circlize)
table <-read.table('test_circos_real_data.txt')
table <- as.matrix(table, c("#FF000080", "#00FF0080", "#0000FF80","#FF000080", "#00FF0080", "#0000FF80"))
rownames(table) = c('car', 'bus','train', 'walk', 'run', 'skip', 'jump')
colnames(table) = c('car', 'bus','train', 'walk', 'run', 'skip', 'jump')
chordDiagram(table)

The output is

here

I know that the colours haven't been set properly, because when I run the code multiple times, the colours change, so I know it's random (even though I tried to set them in the code). At what point in the code, do I set the colours? I would like the colours: red, orange, green, blue, purple, pink etc to be set (trying to avoid dull colours like brown, black, grey).

Thanks.


Solution

  • Try the grid.col argument:

    chordDiagram(table, grid.col = c("red", "blue", "purple","pink", "orange", "green", "steelblue1"))
    

    enter image description here