ggplot:如何将0坐标移动到X轴的中间?

时间:2014-09-16 16:37:35

标签: r plot ggplot2 coordinate

enter image description here

我正在尝试使用以下代码创建火山图,但我想将“0”坐标放在X轴的中间。有没有办法在ggplot中做到这一点?

v<-ggplot(exprData.fil,aes(Effect,Effect.sig))+geom_point(aes(colour=Effect.sig),alpha=0.7)+scale_colour_gradient(low="red",high="green")
    v+ggtitle(mainTitle)
    v+xlab(expression(log[2](bar(After) / bar(Before))))+ylab(expression(-log[10]("p.value"))) 

1 个答案:

答案 0 :(得分:1)

添加scale_x_continuous()以设置轴限制:

v <- ggplot(exprData.fil,aes(Effect,Effect.sig)) +
       geom_point(aes(colour=Effect.sig),alpha=0.7) +
       scale_colour_gradient(low="red",high="green") +
       ggtitle(mainTitle) + 
       xlab(expression(log[2](bar(After) / bar(Before)))) +
       ylab(expression(-log[10]("p.value"))) +
       scale_x_continuous(limits=c(-12,12), breaks=seq(-12,12,2))

另一种选择是使用coord_cartesian(xlim=c(-12,12))。它与scale_x_continuous()之间的主要区别在于,如果您向绘图添加任何数据摘要(如平滑,平均值,箱图等)。如果您的轴限制不包括全部数据值,那么使用scale_x_continuous()(或scale_y_continuous())将导致数据摘要操作排除摘要中的不可见数据,而{ {1}}将包括摘要中的所有数据,无论是否在图中可见。