0

我有两个不同类别的核苷酸序列(A、T、C 和 G 的有序字符序列)的丰度数据。我想使用 ggplot 将覆盖率显示为序列上的线图。我已经走得很远了,还有几个障碍要跳。样本数据:

> dput(so.sample)
structure(list(`1_mes_wt` = c(0, 0, 4.25897346349789, 10.0666645500859, 
10.0666645500859, 48.3974257215669, 78.2102399660521, 250.698665237717, 
250.698665237717, 268.702507606139, 271.79994285232, 301.225577691032, 
301.225577691032, 301.225577691032, 301.225577691032, 311.292242241118, 
311.292242241118, 311.292242241118, 311.292242241118, 311.292242241118, 
311.292242241118, 311.292242241118, 311.292242241118, 311.292242241118, 
311.292242241118, 311.292242241118, 311.292242241118, 321.746086196977, 
321.746086196977, 321.746086196977, 319.616599465228, 308.969165806483, 
285.931991163017, 204.817905653671, 195.332010212244, 170.165348837029, 
170.165348837029, 170.165348837029, 170.165348837029, 37.3628126570497, 
40.8474273090025, 22.456405534807, 22.456405534807, 17.8102526655366, 
17.8102526655366, 17.8102526655366, 17.8102526655366, 17.8102526655366, 
17.8102526655366, 17.8102526655366, 17.8102526655366, 15.6807659337877, 
15.6807659337877, 15.6807659337877, 15.6807659337877, 15.6807659337877, 
15.6807659337877, 15.6807659337877, 15.6807659337877, 15.6807659337877, 
15.6807659337877, 15.6807659337877, 15.6807659337877, 15.6807659337877, 
15.6807659337877, 15.6807659337877, 5.22692197792922, 5.22692197792922, 
5.22692197792922, 5.22692197792922, 5.22692197792922, 5.22692197792922, 
5.22692197792922, 5.22692197792922, 5.22692197792922, 5.22692197792922, 
5.22692197792922, 1.74230732597641, 1.93589702886268, 1.93589702886268, 
4.25897346349789, 2.71025584040775, 2.71025584040775, 68.5307548217387, 
89.6320324363419, 90.0192118421144, 93.310236791181, 93.1166470882947, 
93.5038264940673, 93.8910058998398, 93.8910058998398, 93.8910058998398, 
93.8910058998398, 93.8910058998398, 93.8910058998398, 93.8910058998398, 
93.8910058998398, 93.8910058998398, 93.8910058998398, 93.8910058998398, 
93.8910058998398, 93.8910058998398, 93.8910058998398, 93.8910058998398, 
93.8910058998398, 93.6974161969535, 93.6974161969535, 93.6974161969535, 
93.6974161969535, 93.6974161969535, 93.6974161969535, 93.6974161969535, 
93.6974161969535, 93.6974161969535, 89.2448530305694, 77.2422914516208, 
1.16153821731761, 0, 0, 0, 0), `2_mes_wt` = c(0, 0, 13.3249362857652, 
41.0267775114349, 41.3774337294814, 100.988990797378, 100.988990797378, 
341.188500159198, 343.643093685523, 359.422623497613, 381.163309016493, 
450.242583971645, 450.242583971645, 450.242583971645, 450.242583971645, 
450.242583971645, 450.242583971645, 450.242583971645, 450.242583971645, 
450.242583971645, 450.242583971645, 450.242583971645, 450.242583971645, 
450.242583971645, 450.242583971645, 450.242583971645, 450.242583971645, 
450.242583971645, 450.242583971645, 450.242583971645, 450.242583971645, 
426.047304926439, 366.085091640496, 308.928128098924, 201.977981594756, 
201.977981594756, 205.133887557174, 205.133887557174, 205.133887557174, 
85.5601172033343, 98.8850534890995, 17.1821546842762, 17.1821546842762, 
17.1821546842762, 17.1821546842762, 17.1821546842762, 17.1821546842762, 
16.8314984662297, 16.8314984662297, 16.8314984662297, 16.8314984662297, 
50.8451516167356, 52.5984327069678, 52.5984327069678, 52.5984327069678, 
52.5984327069678, 52.5984327069678, 52.5984327069678, 52.5984327069678, 
52.5984327069678, 52.5984327069678, 52.5984327069678, 52.5984327069678, 
52.5984327069678, 52.5984327069678, 52.5984327069678, 52.5984327069678, 
52.5984327069678, 52.5984327069678, 52.5984327069678, 52.5984327069678, 
52.5984327069678, 52.5984327069678, 52.5984327069678, 52.5984327069678, 
52.5984327069678, 52.5984327069678, 39.2734964212026, 37.5202153309704, 
42.0787461655743, 54.7023700152465, 54.7023700152465, 54.7023700152465, 
113.261958429004, 114.313927083143, 114.313927083143, 116.067208173376, 
82.0535550228698, 82.0535550228698, 82.0535550228698, 82.0535550228698, 
82.0535550228698, 82.0535550228698, 82.0535550228698, 82.0535550228698, 
82.0535550228698, 82.0535550228698, 82.0535550228698, 82.0535550228698, 
82.0535550228698, 82.0535550228698, 82.0535550228698, 82.0535550228698, 
82.0535550228698, 82.0535550228698, 82.0535550228698, 82.0535550228698, 
82.0535550228698, 82.0535550228698, 82.0535550228698, 82.0535550228698, 
82.0535550228698, 82.0535550228698, 82.0535550228698, 74.3391182258479, 
63.4687754664078, 0, 0, 0, 0, 0), nucl = 47738064:47738184, base = c("T", 
"C", "A", "A", "A", "A", "A", "A", "G", "A", "C", "T", "A", "G", 
"T", "C", "A", "A", "G", "T", "G", "C", "A", "G", "T", "A", "G", 
"T", "G", "A", "G", "A", "A", "G", "G", "G", "G", "G", "G", "A", 
"A", "A", "G", "T", "G", "T", "A", "G", "A", "A", "C", "A", "G", 
"G", "A", "G", "T", "T", "C", "A", "A", "T", "C", "T", "G", "T", 
"A", "A", "C", "T", "G", "A", "C", "T", "G", "T", "G", "A", "A", 
"C", "A", "A", "T", "C", "A", "A", "T", "T", "G", "A", "G", "A", 
"T", "A", "A", "C", "T", "C", "A", "C", "T", "A", "C", "C", "T", 
"T", "C", "G", "G", "A", "C", "C", "A", "G", "C", "C", "A", "A", 
"T", "G", "C")), .Names = c("1_mes_wt", "2_mes_wt", "nucl", "base"
), row.names = c(NA, -121L), class = "data.frame")

为了同时显示序列(碱基)和序列位置(nucl),我将位置绘制为因子,然后使用文本几何图形用序列标记轴。它工作得相当好:

pdf("so_sample.pdf",width=15,height=7)
ggplot(melt(so.sample,id.vars=c("nucl","base")), aes(factor(nucl), 
       value, group=variable, colour=variable)) + 
  geom_line() + geom_text(y=-5,size=3,aes(label=base))
dev.off()

在此处输入图像描述

但是,将这些大数字绘制为因素会导致主要重叠,无论如何我都不需要查看每个位置标签。所以我删除了一些休息时间。

pdf("so_sample2.pdf",width=15,height=7)
ggplot(melt(so.sample,id.vars=c("nucl","base")), aes(factor(nucl), 
       value, group=variable, colour=variable)) + 
  geom_line() + geom_text(y=-5,size=3,aes(label=base)) + 
  scale_x_discrete(breaks=seq(min(so.sample$nucl),
                   max(so.sample$nucl),10))
dev.off()

在此处输入图像描述

我快到了,但在删除中断时,我还删除了与字符序列一起特别有用的次要网格线。是否有任何方法可以添加独立于中指定的中断的次要网格线scale_x_discrete

还有一个问题:序列标签之所以有效,是因为它为每个分组在完全相同的位置绘制相同的字符,并且这些标签的最终颜色由绘制组的顺序决定。我希望序列是中性颜色,但我不知道是否甚至可以geom_text独立于分组给出这些值。

4

1 回答 1

1

保持原样nucl而不将其包装在调用中factor允许您使用scale_x_continuous,与 不同scale_x_discrete的是,它有一个minor_breaks参数。

于 2012-09-11T13:11:57.870 回答