我试图创建一个gggplot条形图,其中x轴为基因组起始位置,y轴为高度值。
我有一个3000行的表,我试图绘制它的子集,如下所示:
ggplot(data = chr1[1:4,c(1:3,9,14)]) +
geom_bar(aes(x= start,y=V7), stat="identity")
table的这一部分看起来是这样的
dput(chr1[1:4,c(1:3,9,14)])
structure(list(seqnames = c("chr1", "chr1", "chr1", "chr1"),
start = c(858042L, 858076L, 5955119L, 5955150L), end = c(858192L,
858155L, 5955238L, 5955257L), V7 = c(22.74576, 8.52652, 10.04841,
7.32666), which = c("sorted", "rep3", "rep3", "sorted")), row.names = c(1707L,
1L, 2L, 1708L), class = "data.frame")
seqnames start end V7 which
1707 chr1 858042 858192 22.74576 sorted
1 chr1 858076 858155 8.52652 rep3
2 chr1 5955119 5955238 10.04841 rep3
1708 chr1 5955150 5955257 7.32666 sorted
在这种情况下,我会得到一个空图,图显示在我的设备上,但我没有得到任何条。
如果我试着画出第一个子集
ggplot(data = chr1[1:2,]) +
geom_bar(aes(x= start,y=V7), stat="identity")
我能正常接收信号。
如果我使用填充或颜色我得到所有的酒吧以及你可以看到在下面的下一个问题。
为什么会这样呢?
另外,我想绘制所有的条形图,不使用factor(start),使用透明的alpha填充(column which),这样当它们非常接近时,我就可以看到它们。如果x轴上没有factor,alpha因子似乎不会被应用。
比如这个
ggplot(chr1[1:4,], aes(x=start, y=V7, fill=which, color=which)) +
geom_bar(stat="identity",alpha=0.2) + theme_minimal()
给我的酒吧,但没有透明度应用
有什么变通办法吗?
非常感谢!
1条答案
按热度按时间q3qa4bjr1#
为了说明将
start
作为数字的问题。如果你把
start
变成一个因子,它们将有相似的间距。然而,如果两条线之间的距离很重要,则需要调整
width
参数,但这样做可能会使两条线相互重叠。创建于2023-04-21使用reprex v2.0.2