[R] ggplot2 - expand range?
hadley wickham
h.wickham at gmail.com
Fri Nov 2 17:40:53 CET 2007
Hi Pedro,
You need to set the expand parameter to c(0,0) :
scale_y_continuous(limits=c(0,10), expand = c(0,0))
ggplot uses expand_range internally to ensure that you always have
some space between the data and the margins (and you should make sure
this happens in your plot too - otherwise it can be hard to see data
points on the sides)
Hadley
On 11/1/07, Pedro de Barros <pbarros at ualg.pt> wrote:
> Dear UserRs,
>
> I am trying to use systematically ggplot2 for most of my plots, but I
> am fighting some lack of documentation, which I try to overcome.
>
> I want to build a scatterplot where the axes cross exactly at (0,0).
> I tried using scale_y_continuous(limits=c(0,10)), but I always get an
> extra space at the bottom of the axes. The code I used is below.
>
> > plotdata<-data.frame(x=1:10, y=runif(10))
> > plot<-ggplot()
> > plot<-plot+layer(data=plotdata, mapping=aes_string(x='x',y='y'),
> geom='point', stat='identity', size=4)
> > plot<-plot+ scale_y_continuous(limits=c(0,1))
> > print(plot)
>
> I believe there may be a way to use expand_range to fix this (I think
> I read about it somewhere), but I do not seem to find out how.
> I have searched the ggplot help and
> the archives, but cannot find the answer to this issue.
> I would really appreciate if anyone could give me a pointer.
>
> I am using R2.6.0 (patched) on Windows
>
> Thanks,
> Pedro
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
http://had.co.nz/
More information about the R-help
mailing list