tags:

views:

79

answers:

2

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_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

+2  A: 

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.

Matt Parker
Perfect, that worked great. Thanks!
Maiasaura
+2  A: 

Here is another solution:

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

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

rcs