1

I am writing because I would like to get some help with a plot in R, using the package circlize, please.

I am trying to make a chord diagram, and I could make it, but the names on the plot are overlapped,

enter image description here

then I tried with a code that I picked up from: and I got the same plot, but with the names repeated, and overlapped on each other enter image description here

the code that I am using for my plot is

chordDiagram(as.matrix(naxo2)
         ,grid.border = 1,
         grid.col = NULL,
         transparency = 0.5,
         preAllocateTracks = 0)

and the data frame already has the names included in the matrix that I am using.

what I would like to get is a plot in which the names appear in a 90 degrees to avoid the overlapping.

Any help is very welcome, and thanks in advance!

PS: I also tried the another solution that was posted here, but I did not work for me (R: Adjusting Labels in circlize diagram)

agstudy
  • 119,832
  • 17
  • 199
  • 261
naxo
  • 11
  • 2
  • Search for D3 charts in R. https://d3js.org/ – M.Qasim Jun 25 '17 at 21:36
  • Looks that you should use `circos.trackPlotRegion` and use a special `panel.fun` , take a look [here](https://stackoverflow.com/questions/31943102/rotate-labels-in-a-chorddiagram-r-circlize). – agstudy Jun 25 '17 at 21:49
  • You can refer to http://zuguang.de/circlize_book/book/advanced-usage-of-chorddiagram.html#customize-sector-labels – Zuguang Gu Jul 17 '17 at 14:44

1 Answers1

2

Please next time provide the data needed to reproduce your example.

The idea is to plot the diagram first without labels, and then add the text selecting for the argument facing one of the options that rotate the labels, e.g. clockwise. Here one example

data("cars")

# Clockwise labels may require increasing the canvas margins
circos.par(canvas.xlim=c(-1.5,1.5),canvas.ylim=c(-1.5,1.5))
df.test=df[,c(1,2)]

cDiag = chordDiagram(df.test, 
             #directional = 2, 
             annotationTrack = "grid")

for(si in get.all.sector.index()) {
  xlim = get.cell.meta.data("xlim", sector.index = si, track.index = 1)
  ylim = get.cell.meta.data("ylim", sector.index = si, track.index = 1)
  circos.text(mean(xlim),ylim[1], si, sector.index = si, track.index = 1, 
              facing = "clockwise", 
              cex=0.8, 
              adj=c(-1,0),
              niceFacing = TRUE)
  circos.axis(h = 0,
              major.at = c(0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5) ,
              labels.cex = 0.2,labels.facing = "inside", 
              sector.index = si, track.index = 1)
}


circos.clear()

chord Diagram clockwise labels

Alf Pascu
  • 365
  • 3
  • 11