Rotate labels in a chordDiagram (R circlize)

限于喜欢 提交于 2019-11-29 18:57:59

问题


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 the labels 90 degrees to they are perpendicular to the circle?

library(circlize)
set.seed(999)
mat = matrix(sample(18, 18), 3, 6)
rownames(mat) = paste0("Start", 1:3)
colnames(mat) = paste0("End", 1:6)
chordDiagrm(mat)

In the figure below I manually inserted a few labels to show what I hope to accomplish (End5, End6, End7). Thanks.


回答1:


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:



来源:https://stackoverflow.com/questions/31943102/rotate-labels-in-a-chorddiagram-r-circlize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!