由于您是以圆形方式呈现染色体,请尝试使用 Bioconductor 提供的 ecolitk 软件包提供的工具,其中包括用于在圆形染色体上绘制各种形状的工具。
ETA:这是一个使用它来创建圆形条形图的示例,尽管它只是触及了您可以用它做的事情的表面。
library(ecolitk)
plot.new()
plot.window(c(-5, 5), c(-5, 5))
plot.chrom = function(data, chromlength, radius=1,
width=chromlength/length(data), ...) {
linesCircle(radius, ...)
starts = seq(1, chromlength - width, width)
scale = .5 / max(abs(data))
for (i in 1:length(starts)) {
polygonChrom(starts[i], starts[i]+width, chromlength, radius,
data[i] * scale + radius, ...)
}
}
plot.chrom(rnorm(100, 10, 1), 10000, radius=1)
plot.chrom(rnorm(100, 10, 2), 10000, radius=2, col="blue")
plot.chrom(rnorm(100, 10, 5), 10000, radius=3, col="red")
plot.chrom(rnorm(100, 10, 10), 10000, radius=4, col="green")
legend("topright", legend=c("chr1", "chr2", "chr3", "chr4"),
col=c("black", "blue", "red", "green"), lty=1)
ETA:啊,现在我明白你所说的分区是什么意思了。在这种情况下,此代码应该是您要查找的代码。它使用您提供的数据(稍作修改 - 我必须为染色体列命名,以便我可以使用 ddply )并允许您指定染色体之间的间距。虽然我没有对其进行深入测试,但改变个体染色体长度以及模拟数据的均值和方差之类的东西应该可以按您的预期工作。
plot.multi.chrom = function(data, colors, spacing=50) {
plot.new()
plot.window(c(-5, 5), c(-5, 5))
lengths = ddply(data, .(chr), function(x) max(x$position))
nchrom = NROW(lengths)
offsets = cumsum(c(0, lengths[, 2])) + cumsum(c(0, rep(spacing, nchrom)))
tot.length = offsets[length(offsets)] + spacing
scales = .75 / apply(abs(data[, 3:NCOL(data)]), 2, max)
for (i in 1:NROW(data)) {
for (j in 3:NCOL(data)) {
start = offsets[data[i, 1]] + data[i, 2]
polygonChrom(start, start + 1, tot.length,
j - 2, data[i, j] * scales[j - 2] + j - 2,
col=colors[j - 2])
}
}
}
chr <- rep (1:4, each = 200)
position <- c(1:200, 1:200, 1:200, 1:200)
v1bar <- rnorm(800, 10, 2)
v2bar <- rnorm(800, 10, 2)
v3bar <- rnorm(800, 10, 2)
mydata <- data.frame(chr=chr, position, v1bar, v2bar, v3bar)
require(plyr)
plot.multi.chrom(mydata, colors=c("red", "black", "green"), spacing=50)
legend("topright", legend=c("V1", "V2", "V3"),
col=c("red", "black", "green"), lty=1)