Skip to content

ggplot2 geom_abline slope not working?

2 messages · xiechao, Hadley Wickham

#
I am learning ggplot2, and need your help.

When I try
(from http://had.co.nz/ggplot2/geom_abline.html)

the slope of the abline does not change, but this works:
In order to have slope work, I have to use
Is it a bug, or is there some reason slope and intercept were treated
differently?

Thank you very much in advance for your clarification.
#
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: