[R] ggplot2 geom_abline slope not working?

hadley wickham h.wickham at gmail.com
Thu Nov 8 16:37:21 CET 2007


Ooops - yes that's a bug!  It'll be fixed in the next version of
ggplot, or you can run this code to fix it yourself:

GeomAbline$new <- function(., mapping=aes(), data=NULL, intercept=0,
slope=1, ...) {
    if (missing(data)) {
      data <- data.frame(intercept = intercept, slope=slope)
    }
    mapping <- defaults(mapping, aes(intercept=intercept, slope=slope,
x=NULL, y=NULL, group=1))
    class(mapping) <- "uneval"

    layer(mapping=mapping, data=data, geom = ., geom_params = list(...))
  }

Hadley

On 11/8/07, xiechao <sleepingcell at gmail.com> wrote:
>
> I am learning ggplot2, and need your help.
>
> When I try
>
> > p <- ggplot(mtcars, aes(x = wt, y=mpg)) + geom_point()
> > p + geom_abline(slope=5)
> (from http://had.co.nz/ggplot2/geom_abline.html)
>
> the slope of the abline does not change, but this works:
> > p + geom_abline(intercept=20)
>
> In order to have slope work, I have to use
> > p + geom_abline(aes(slope=5))
>
> Is it a bug, or is there some reason slope and intercept were treated
> differently?
>
> Thank you very much in advance for your clarification.
>
> --
> View this message in context: http://www.nabble.com/ggplot2-geom_abline-slope-not-working--tf4770727.html#a13646422
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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