I tried this (from page 40, just changing object name)
p <- ggplot(diamonds, aes(carat, price, color = cut))
p2 <- p + layer(geom = "point")
p3 <- p + layer( geom = "bar",
geom_params = list(fill = "steelblue"),
stat = "bin",
stat_params = list(binwidth = 2))
p, as appropriate, gives an error of no layer
p2 works fine
p3 gives an error:
in eval(expr, envir, enclos) : object "y" not found
which is not clear, at least, not to me ....
TIA
Peter
Peter L. Flom, PhD
Statistical Consultant
www DOT peterflomconsulting DOT com
This is a little complicated to explain - but it's due to the
interaction of the statistics and the geom. The bin statistic
basically ignores the y value in the original dataset, and returns a
data frame with columns x, width, count and density (plus a few
others). Usually, the y mapping defaults to the ..count.. (the dots
meaning to use the count variable from the statistic, not the original
data), but you've overridden that so the y value is not mapped to
anything after the stat is run, and you get the error. Does that make
sense?
Hadley