R 创建一个几何柱状图,该柱状图对正/负图形进行计数

R 创建一个几何柱状图,该柱状图对正/负图形进行计数,r,ggplot2,R,Ggplot2,我在绘制正y轴上的正log2_比率计数和负y轴上的负log2_比率计数时遇到问题 本质上,我希望正计数在x轴之上,而负计数在x轴之下 以下是数据帧和代码: chrom chr_start chr_stop num_positions normal_depth tumor_depth log2_ratio gc_content sample 324202 1 156249804 156249858 55 12.3

我在绘制正y轴上的正
log2_比率
计数和负y轴上的负
log2_比率
计数时遇到问题

本质上,我希望正计数在x轴之上,而负计数在x轴之下

以下是数据帧和代码:

   chrom      chr_start   chr_stop     num_positions normal_depth tumor_depth log2_ratio gc_content sample
   324202     1 156249804 156249858            55         12.3         4.7     -1.399       34.5     10
   324203     1 156250463 156250473            11         10.0         4.6     -1.109       27.3     10
   324204     1 156250664 156250705            42         12.0         7.4     -0.704       19.0     10
   324205     1 156250816 156250847            32         11.7         4.6     -1.343       40.6     10
   324206     1 156251108 156251132            25         10.6         3.6     -1.569       60.0     10
   324207     1 156251411 156251464            54         12.3         6.8     -0.863       46.3     10

newHist = ggplot(resultsPileup1COMBINED[resultsPileup1COMBINED$sample <= 25,],
          aes(x=sample)) +
          geom_histogram(fill="blue" , bindwidth = 1) +
          geom_histogram(data=resultsPileup1COMBINED[resultsPileup1COMBINED$sample > 25,],
            fill="gray50" , binwidth = 1) +
            scale_x_continuous(breaks = seq(from = 1, to = 50, by = 3))
chrom chr\u start chr\u stop num\u位置正常\u深度肿瘤\u深度log2\u比率gc\u含量样本
324202     1 156249804 156249858            55         12.3         4.7     -1.399       34.5     10
324203     1 156250463 156250473            11         10.0         4.6     -1.109       27.3     10
324204     1 156250664 156250705            42         12.0         7.4     -0.704       19.0     10
324205     1 156250816 156250847            32         11.7         4.6     -1.343       40.6     10
324206     1 156251108 156251132            25         10.6         3.6     -1.569       60.0     10
324207     1 156251411 156251464            54         12.3         6.8     -0.863       46.3     10
newHist=ggplot(resultsPileup1COMBINED[resultsPileup1COMBINED$sample 25,],
fill=“gray50”,binwidth=1)+
比例x连续(中断=顺序(从=1到=50,按=3))
以下是当前图表:


如果您想要一个全新的图表,请尝试:

ggplot() + geom_histogram(data = resultsPileup1COMBINED[resultsPileup1COMBINED$log2_ratio > 0, ], 
                          aes(x = log2_ratio, y = ..count..)) + 
           geom_histogram(data = resultsPileup1COMBINED[resultsPileup1COMBINED$log2_ratio < 0, ], 
                          aes(x = - log2_ratio, y = - ..count..))
同样,休息和颜色由你决定

要使其与原始绘图相似,请确保包括:

scale_x_discrete(breaks = seq(from = 1, to = 50, by = 3))

geom_直方图(data=resultsPileup1COMBINED,aes(x=log2_比率,y=-…计数…)不一定创建负对数和正对数2_比率的计数。它看起来像是在创建一个负log2_比率值的总和,并且出于某种原因,对x=-1、-2和-3进行绘图。正计数在x轴上方,负计数在x轴下方。由于某些原因,它看起来不正确。例如,对于患者2,我在问题中发布的图表的计数约为210。新图形的计数小于此值。在graphingit没有删除之前,我删除了所有NAs或0。正对数和负对数之和为3332,而nrows为3344。此外,还有12个log2_比率等于0。对不起,我一定漏掉了一些0。图表应该匹配,但不幸的是不匹配。
scale_x_discrete(breaks = seq(from = 1, to = 50, by = 3))