继几年前的这个例子之后,我想chordDiagram
使用circlize
R 中的包对a 中的段标签进行颜色编码。
中的文档?circos.text
告诉我,我应该使用col
图形par
参数中的参数来设置 this。但是,par(col)
不接受颜色向量。
有人可以建议如何做到这一点吗?非常感谢。
circlize
此处使用R 中的包的示例代码。
library(circlize)
set.seed(999)
## generate example data
mat <- matrix(sample(18, 18), 3, 3)
rownames(mat) <- colnames(mat) <- paste0("A", 1:3)
df = data.frame(from = rep(rownames(mat), times = ncol(mat)),
to = rep(colnames(mat), each = nrow(mat)),
value = as.vector(mat),
stringsAsFactors = FALSE)
## set colours for segments
grid.col <- setNames(rainbow(nrow(mat)), rownames(mat))
# now, plot the image with rotated labels
chordDiagram(df, annotationTrack = "grid",
preAllocateTracks = 1,
grid.col = grid.col,
directional = 1,
direction.type = c("diffHeight", "arrows"),
link.arr.type = "big.arrow")
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.5, 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)
这产生了这个漂亮的情节
如何将标签 A1、A2 和 A3 更改为与其段相同的颜色?par(col = grid.col)
不起作用,因为它只需要向量中的一种颜色。非常感谢。
> sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS High Sierra 10.13.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats4 parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_3.3.1 reshape2_1.4.4 pRolocdata_1.26.0 pRoloc_1.29.0
[5] BiocParallel_1.22.0 MLInterfaces_1.68.0 cluster_2.1.0 annotate_1.66.0
[9] XML_3.99-0.3 AnnotationDbi_1.50.0 IRanges_2.22.2 MSnbase_2.14.2
[13] ProtGenerics_1.20.0 S4Vectors_0.26.1 mzR_2.22.0 Rcpp_1.0.4.6
[17] Biobase_2.48.0 BiocGenerics_0.34.0 dplyr_1.0.0 circlize_0.4.9
[21] migest_1.8.1