设置在ggplot2 geom_bar中使用对数刻度时y轴平分的位置

时间:2017-04-03 20:39:13

标签: r plot ggplot2 axis geom-bar

我试图创建一个对数转换的基因表达数据的条形图,但我似乎无法改变我的x和y轴之间的交叉区域。我可以在R基础上做到这一点,但这是更广泛的Shiny应用程序的一部分,我希望图之间的一致性。这是一个最小的例子:

df <- structure(list(Genes = 1:96, foldExpression = c(0.0004815809133408, 
0.000186554083405159, 0.000142020245166264, 9.91580733203794e-05, 
1.50586731037356e-06, 0.00481620829848941, 7.00667826311261e-06, 
0.000604779718674668, 0.163676740192247, 3.62788104054902, 2.44658474904461e-05, 
0.210999773018998, 1.32242024147151e-05, 4.45630431051514e-05, 
0.0125863492990385, 2.49268008840451e-06, 1.50586731037356e-06, 
3.02807684233181e-06, 3.50705461319705e-06, 0.000105632409818916, 
1.19134216162706e-05, 1.29449671876212e-05, 9.74212165299063e-06, 
3.63184214547378e-05, 3.26242458235749e-06, 0.000181524513078334, 
34.0598396752968, 0.000640482203907824, 0.146425597192933, 0.0211590493748083, 
0.00269592092938944, 8.12671770229108e-06, 0.191107177896105, 
0.0330151237231742, 0.000562693414872207, 0.0343156883059605, 
0.138685187592148, 1.50414231710658e-06, 0.000906002611814846, 
1.50586731037356e-06, 0.00070179892741303, 1.64817643465276e-05, 
0.0204972580462547, 0.99689996775548, 5.73398819576538e-06, 0.00172777432122405, 
0.000320413861481815, 1.55703647256429e-05, 4.93694330997287e-05, 
0.00048347227858637, 16.2495902202441, 0.000117459820797509, 
0.46855520182516, 0.187167487209099, 0.0126360264277908, 0.547826527450132, 
0.00010186283275126, 0.107099888658231, 0.928988877390118, 0.0255891506765197, 
14.5878478488994, 0.0351486534651654, 1.50586731037356e-06, 0.12898863274561, 
1.07807490617892e-06, 0.0866906132169558, 0.0846439755023068, 
1.50586731037356e-06, 0.0219408065875584, 0.000633712919015739, 
1.34286645334472, 0.000781651675786721, 0.00111374027766133, 
1.68108995564353, 0.000296064304023605, 0.00553646319822078, 
0.00406191327455512, 0.00597091227977721, 0.000671556330036686, 
0.000494591352109571, 5.85672221179354e-05, 0.0011496215564835, 
0.00382596985799774, 0.35229799361084, 1.04529619268133e-06, 
0.33618336876906, 0.369380625212315, 0.357075757608649, 1.38899057059804, 
1.43890812412937, 0.839895749200342, 0.0188847113666784, 18.005148013488, 
1.3403885084613, 2.74237272274652, 1.38899057059804)), .Names = c("Genes", 
"foldExpression"), row.names = c(NA, -96L), class = "data.frame")

ggplot(df, aes(Genes, foldExpression))+
geom_bar(stat='identity')+
scale_y_log10(breaks=trans_breaks("log10", function(x) 10^x), labels=trans_format("log10",math_format(10^.x)))

enter image description here

实际上很多酒吧看起来都很棒。否定因为y截取为1.理想情况下,我想概括一下合作者在Excel中制作的内容,其中y轴与x的横截面为0.001,并且未绘制低于此值的值(或绘制为0.001)。

使用ggplot2有一种简单的方法吗?我一直在关注scale_y_continuous()和expand_limits(),但是虽然我可以改变比例,但我无法改变截距。我能想到的最好的就是用geom_crossbar函数强制它来获取我正在寻找的情节:

df$foldExpression[which(df$foldExpression < 0.001)] <- 0.001
ggplot(df, aes(Genes, foldExpression))+
geom_crossbar(aes(ymin=0.001, ymax=foldExpression))+
scale_y_log10(breaks=trans_breaks("log10", function(x) 10^x), labels=trans_format("log10",math_format(10^.x))

enter image description here

但这看起来有点奇怪,因为中间&#39;属性在栏顶部可见,而且它是空洞的,所以我不认为我可以填充&#39;盒子。

非常感谢任何帮助!

0 个答案:

没有答案