旋转和弦中的标签 [英] Rotate labels in a chordDiagram (R circlize)

查看:259
本文介绍了旋转和弦中的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是circlize包中的一些代码,用于创建和弦图.是否可以将标签垂直于圆形旋转90度?

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)

在下图中,我手动插入了一些标签以显示希望完成的操作(End5,End6,End7).谢谢.

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

推荐答案

根据您的示例数据,这是一种实现方法:

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)

结果:

这篇关于旋转和弦中的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆