我想使用我们的数据在此处发布类似的图表,但是,我收到了此错误消息“检测一些间隙太大”。您认为是因为某些值与其他值相比非常小(例如,1 与 1812)吗?我通过在 1 或 2 之后添加几个零,对矩阵 2 中的数据进行了一些更改,它可以工作。有什么方法可以解决这个范围的数据吗?我想用我的真实数据(矩阵 1)绘制这个漂亮的图表。任何帮助深表感谢。
library(circlize)
#matrix 1
#level0 <- c(1, 8, 39, 14, 2)
#level1 <- c(1, 19, 153, 93, 1)
#level2 <- c(2, 19, 274, 46, 13)
#level3 <- c(0, 8, 152, 1812, 465)
#level4 <- c(0, 2, 1, 164, 226)
#matrix 2
#level0 <- c(100,8,39,14,200)
#level1 <- c(100,190, 153,93,100)
#level2 <- c(200,19,274,646,130)
#level3 <- c(200,800,152,1812,465)
#level4 <- c(200,200,100,164,226)
#build matrix 2
a <- list(c(100,8,39,14,200),c(100,19, 153,93,100), c(200,19,274,646,13), c(200,8,152,1812,465),c(200,200,100,164,226))
mat <- do.call(rbind, a)
#mat = matrix(sample(1:100, 25, replace = TRUE), 5, 5)
rownames(mat) = c("level 0", "level 1", "level 2", "level 3", "level 4")
colnames(mat) = c("Level0", "Level1", "Level2", "Level3", "Level4")
rn = rownames(mat)
cn = colnames(mat)
factors = c(rn, rev(cn))
factors = factor(factors, levels = factors)
col_sum = apply(mat, 2, sum)
row_sum = apply(mat, 1, sum)
xlim = cbind(rep(0, 10), c(row_sum, col_sum))
par(mar = c(1, 1, 1, 1))
circos.par(cell.padding = c(0, 0, 0, 0), clock.wise = FALSE, track.margin=c(0,0.1),
gap.degree = 4, start.degree =90)
circos.initialize(factors = factors, xlim = xlim
, sector.width = c(row_sum/sum(row_sum), col_sum/sum(col_sum)))
circos.trackPlotRegion(factors = factors, ylim = c(0, 1), bg.border = NA,
# bg.col = c("red", "orange", "yellow", "green", "blue", rep("grey", 5)), track.height = 0.05,
bg.col = c(c("red", "orange", "yellow", "green", "blue"),
c("blue", "green", "yellow", "orange", "red")), track.height = 0.05,
panel.fun = function(x, y) {
sector.name = get.cell.meta.data("sector.index")
xlim = get.cell.meta.data("xlim")
circos.text(mean(xlim), 3, sector.name, adj = c(0.5, 0))
circos.axis(labels.cex=0.8, direction="outside", labels.away.percentage=0.5)
if(sector.name %in% rn) {
for(i in seq_len(ncol(mat))) {
circos.lines(rep(sum(mat[sector.name, seq_len(i)]), 2), c(0, 1),
col = "white")
}
} else if(sector.name %in% cn) {
for(i in seq_len(nrow(mat))) {
circos.lines(rep(sum(mat[ seq_len(i), sector.name]), 2), c(0, 1),
col = "white")
}
}
})
col = c("#FF000020", "#FFA50020", "#FFFF0020", "#00FF0020", "#0000FF20")
for(i in seq_len(nrow(mat))) {
for(j in seq_len(ncol(mat))) {
circos.link(rn[i], c(sum(mat[i, seq_len(j-1)]), sum(mat[i, seq_len(j)])),
cn[j], c(sum(mat[seq_len(i-1), j]), sum(mat[seq_len(i), j])),
col = col[i], border = "white")
}
}