I'm trying to learn ggplot2
to apply it to my own data, but have encountered a problem when trying to reproduce a plot from the book 'Elegant Graphics for Data Analysis' by Hadley Wickham (Fig 4.10 (right), chapter 4: 4.9.1 Combining geoms and stats, p. 61) using the following code:
d <- ggplot(diamonds, aes(carat)) + xlim(0, 3)
d + stat_bin(aes(y = 1, fill = ..count..), binwidth = 0.1, geom = "tile", position="identity")
It results in the following error message:
# Error : Mapping a variable to y and also using stat="bin".
# With stat="bin", it will attempt to set the y value to the count of cases in each group.
# This can result in unexpected behavior and will not be allowed in a future version of ggplot2.
# If you want y to represent counts of cases, use stat="bin" and don't map a variable to y.
# If you want y to represent values in the data, use stat="identity".
# See ?geom_bar for examples. (Defunct; last used in version 0.9.2)
How can I reproduce the desired plot/fix the error? Could you please explain it bit if possible. How could the same kind of plot be produced using geom_tile
?
Thank you very much for your help!!