我这里有这个数据文件https://www.dropbox.com/s/hei2fa25r9ezvkx/myfile.csv?dl=0
我想绘制chr1到chr16起始位置的密度图。所以我想将X轴分区为chr1,chr2,chr3,.. chr16,并且在每个chr分区内,我想得到每个起始位置的density
图。我希望在Y轴上绘制density
变量。我尝试了类似于here的内容,但它没有将每个chr组中的Y轴和它们各自的起始位置划分为X轴。有人可以帮我策划这个。谢谢!
args = commandArgs(trailingOnly=TRUE)
inFn = args[1]
outFn = args[2]
title = args[3]
xRange <- range(0, d$stop)
yRange <- range(0, d$density)
pdf(outFn)
plot(xRange, yRange, type="l", xlab="Position", ylab="Density", main=title)
lines(d$start, d$density)
dev.off()
更新了可重现的数据:
d<- structure(list(chr = c("chr10", "chr10", "chr10", "chr10", "chr1",
"chr1", "chr1", "chr1", "chr1", "chr1", "chr3", "chr3", "chr3",
"chr3", "chr3", "chr3"), start = c(6, 14, 19, 24, 8442, 8446,
8487, 8489, 8491, 8497, 13282, 13324, 13325, 13328, 13366, 13368
), stop = c(6, 14, 19, 24, 8442, 8446, 8487, 8489, 8491, 8497,
13282, 13324, 13325, 13328, 13366, 13368), density = c(10, 4,
1, 3, 9, 62, 43, 115, 419, 2, 982, 57, 14, 248, 16, 1)), .Names = c("chr",
"start", "stop", "density"), row.names = c(1L, 2L, 3L, 4L, 6000L,
6001L, 6002L, 6003L, 6004L, 6005L, 10000L, 10001L, 10002L, 10003L,
10004L, 10005L), class = "data.frame")
答案 0 :(得分:2)
我不时会像这样绘制数据,而且我总是使用geom_point
。如果染色体中存在间隙(即,着丝粒),则geom_bar
过于堆叠且geom_line
看起来很糟糕。
你可以试试这个:
library(ggplot2)
ggplot(d, aes(start, density)) +
geom_point(alpha = 0.9) +
facet_grid(. ~ chr) +
labs(title = "Density profiles along the chromosomes",
x = "Coordinate, bp",
y = "Density") +
theme_bw()
您可以使用facet_grid(. ~ chr, scales = "free")
“放大”每个染色体中的特定区域。