开发者

How do I make the y-axis intersect the x-axis at 0 in ggplot2?

开发者 https://www.devze.com 2023-01-05 08:12 出处:网络
So when I make plots sometimes I see the y crossing x at some offset. I generated this figure using: ggplot(data=d2,aes(y=log10(Nems+1),x=Time)) +

So when I make plots sometimes I see the y crossing x at some offset. I generated this figure using:

ggplot(data=d2,aes(y=log10(Nems+1),x=Time)) +
  geom_point(size=3,shape=1) +        
  geom开发者_如何学C_line(data=d2,aes(x=time_model,y=log10(value),group=variable,linetype=variable)) +
  ylim(0.001,2) + no_bg + draw_axis

I end up manually moving the y in Illustrator. Is there a way to just do it here?

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


Here is another solution:

... + scale_x_continuous(expand=c(0,0))

See also this related question: Margin adjustments when using ggplot’s geom_tile()


Try adding this to your plot: + coord_cartesian(xlim = c(0, 90))

That should limit the x-axis to 0 through 90.

You could also do + xlim(0, 90), which has a similar effect - but also removes any data outside of its bounds from the dataset. That can be problematic if you're trying to zoom in on features of geoms that should be calculated using the whole dataset (e.g., smooths) because it recalculates those geoms based only on what's inside the limits. coord_cartesian() calculates all the geoms from the full dataset, then limits the window to what you specify.

0

精彩评论

暂无评论...
验证码 换一张
取 消