简体   繁体   English

如何为圆图的每个扇区指定单独的y轴限制集?

[英]How do you specify seperate sets of y axis limits for each sector of a circlize plot?

I have three sets of data that I want to plot using Circlize. 我想使用Circlize绘制三组数据。 Set's "a" and "b" contain positive and negative values, set "c" contains only positive values. 集合的“ a”和“ b”包含正值和负值,集合“ c”仅包含正值。 I want to plot using a consistent y axis for "a" and "b" and different one for "c". 我想对“ a”和“ b”使用一致的y轴,对“ c”使用不同的y轴进行绘图。 Unfortunately, I can't find a way of doing this. 不幸的是,我找不到解决办法。

The code i'm using is below, I seem to only be able to have unique y axis for each or a fixed y axis for all (if you uncomment "ylim..." in the code). 我正在使用的代码如下,我似乎只能为每个代码分配唯一的y轴,或者为所有代码分配一个固定的y轴(如果您在代码中取消注释“ ylim ...”)。

I've tried a few things, trying to loop through using the circos.lines() function instead but this didn't solve it. 我已经尝试了一些方法,尝试使用circos.lines()函数进行循环,但这并不能解决问题。

circos.info() shows separate y axis limits so i think it should be possible. circos.info()显示了单独的y轴限制,因此我认为应该可行。

Thanks in advance. 提前致谢。

library("circlize")
library("reshape")


#--- Data ---#

a <- sort(rnorm(100,0,10))
b <- sort(rnorm(100,0,5))
c <- abs(rnorm(100,0,200))

data <- cbind("a" = a, "b" = b, "c" = c)
data_melt <- melt(data)


#--- Plotting ---#

circos.initialize(      factors = data_melt$X2, 
                        x = data_melt$X1, 
                        sector.width = 1
                        )   

circos.trackPlotRegion( factors = data_melt$X2, 
                        y = data_melt$value, 
#                       ylim = range(data_melt$value),
                        force.ylim = FALSE, 
                        panel.fun = function(x, y) { circos.axis( ) }
                        )

circos.trackLines(      data_melt$X2, 
                        data_melt$X1, 
                        data_melt$value, 
                        type = "h",
                        col = "grey",
                        lwd = 3, 
                        baseline = 0)`

circos.info(sector.index = NULL, track.index = 1)

ylim can be matrix in which each row corresponds to the y-range in each sector. ylim可以是矩阵,其中每一行对应于每个扇区的y范围。

set.seed(123)
a <- sort(rnorm(100,0,10))
b <- sort(rnorm(100,0,1))
c <- abs(rnorm(100,0,200))

data <- cbind("a" = a, "b" = b, "c" = c)
data_melt <- melt(data)


#--- Plotting ---#
r_ab = range(data_melt[data_melt$X2 != "c", "value"])
r_c = range(data_melt[data_melt$X2 == "c", "value"])

circos.par(gap.degree = 5)
circos.initialize(      factors = data_melt$X2, 
                        x = data_melt$X1, 
                        sector.width = 1
                        )   

ylim = rbind(r_ab, r_ab, r_c)
circos.trackPlotRegion( factors = data_melt$X2, 
                        x = data_melt$X1,
                        y = data_melt$value, 
                        ylim = ylim,
                        force.ylim = F, 
                        panel.fun = function(x, y) { 
                            circos.lines(x, y, type = "h", col = "grey", lwd =3, baseline = 0)
                            circos.axis(labels.cex = 0.6) 
                            circos.yaxis(labels.cex = 0.6)
                        }
                       )
circos.clear()

I also moved the code from circos.trackLines() to panel.fun() (because I think panel.fun() is more flexible to add multiple layers of graphics). 我还将代码从circos.trackLines()移到panel.fun() (因为我认为panel.fun()可以更灵活地添加多层图形)。

Also I added circos.yaxis() because y-axis has different ranges in sectors, it is important to explicitly show the y-ranges. 我还添加了circos.yaxis()因为y轴在扇区中具有不同的范围,因此明确显示y范围很重要。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM