Change range in chord diagram in R

143 Views Asked by At

I have a correlation matrix in R as follows:

dat <- as.matrix(cbind(c(1.0000000, 0.5161944, 0.5190630, 0.3717464, 0.5719125),
               c(0.5161944, 1.0000000, 0.2549985, 0.8469740, 0.7761113),
               c(0.5190630, 0.2549985, 1.0000000, 0.2130771, 0.2930945),
               c(0.3717464, 0.8469740, 0.2130771, 1.0000000, 0.5652874),
               c(0.5719125, 0.7761113, 0.2930945, 0.5652874, 1.0000000))
)
colnames(dat) <- c(paste0("X",1:ncol(dat)))
rownames(dat) <- c(paste0("X",1:ncol(dat)))

and I want to create a chord diagram in order to visualise to correlations. I used the following code in order to create a simple version:

circos.par(gap.degree = 0.8)
chordDiagram(dat, transparency = 0.5)

which results in something like this: enter image description here

How can I change the grid values in each X, I want to display them from 0 to 1 with step 0.25. Is that possible based on the function that I used?

1

There are 1 best solutions below

1
L-- On BEST ANSWER

In chordDiagram you can specify:

  • scale = T for the axis to go from 0 to 1
  • annotationTrack = c("name", "grid") for the function not to generate the x axis (the default is annotationTrack = c("name", "grid", "axis"))
circos.clear()
circos.par(gap.degree = 0.8)
chordDiagram(dat, transparency = 0.5, scale = T, annotationTrack = c("name", "grid"))

Then you can manually generate the x axis of each sector using circos.xaxis:

for (i in 1:ncol(dat)) {
  circos.xaxis(sector.index = paste0("X", i), 
               major.at = seq(0, 1, .25), 
               minor.ticks = 0, 
               labels.cex = .5)
}

enter image description here