Rotate labels in a chordDiagram (R circlize)

前端 未结 1 923
天涯浪人
天涯浪人 2020-12-16 15:24

Here is some code from the circlize package for creating a chord diagram.Right now the labels are parallel to the edge of the circle. Is it possible to rotate

相关标签:
1条回答
  • 2020-12-16 16:16

    Based on your example data, here's one way to do it:

    grid.col <- setNames(rainbow(length(unlist(dimnames(mat)))), union(rownames(mat), colnames(mat)))
    par(mar = c(0, 0, 0, 0), mfrow = c(1, 2))
    
    # original image
    chordDiagram(mat, grid.col = grid.col) 
    
    # now, the image with rotated labels
    chordDiagram(mat, annotationTrack = "grid", preAllocateTracks = 1, grid.col = grid.col)
    circos.trackPlotRegion(track.index = 1, panel.fun = function(x, y) {
      xlim = get.cell.meta.data("xlim")
      ylim = get.cell.meta.data("ylim")
      sector.name = get.cell.meta.data("sector.index")
      circos.text(mean(xlim), ylim[1] + .1, sector.name, facing = "clockwise", niceFacing = TRUE, adj = c(0, 0.5))
      circos.axis(h = "top", labels.cex = 0.5, major.tick.percentage = 0.2, sector.index = sector.name, track.index = 2)
    }, bg.border = NA)
    

    Result:

    0 讨论(0)
提交回复
热议问题