如何在ggplot2中使y轴与x轴相交为0?

Mai*_*ura 8 r ggplot2

因此,当我制作情节时,我会看到y交叉x处于某个偏移处.我使用以下方法生成此图:

ggplot(data=d2,aes(y=log10(Nems+1),x=Time)) +
  geom_point(size=3,shape=1) +        
  geom_line(data=d2,aes(x=time_model,y=log10(value),group=variable,linetype=variable)) +
  ylim(0.001,2) + no_bg + draw_axis
Run Code Online (Sandbox Code Playgroud)

我最终在Illustrator中手动移动y.有没有办法在这里做到这一点?

alt text http://img816.imageshack.us/img816/7633/testzh.png

rcs*_*rcs 9

这是另一个解决方案:

... + scale_x_continuous(expand=c(0,0))
Run Code Online (Sandbox Code Playgroud)

另请参阅此相关问题:使用ggplot时的保证金调整geom_tile()


Mat*_*ker 6

尝试将此添加到您的情节: + coord_cartesian(xlim = c(0, 90))

这应该将x轴限制为0到90.

您也可以这样做+ xlim(0, 90),它具有类似的效果 - 但也会从数据集中删除其边界之外的任何数据.如果你试图放大应该使用整个数据集计算的geom的特征(例如,smooths),这可能会有问题,因为它只根据限制内的内容重新计算这些geom.coord_cartesian()从完整数据集计算所有geom,然后将窗口限制为您指定的内容.