I also see differences in R 2.14 so I think the change comes from ggplot 0.9 vs 0.8.9 rather than from R 2.14 vs R 2.15.
It's not a graphic device or platform thing either (and it shouldn't be) since I see the same graph Tyler posted but I am on OS X with a quartz device.
I suspected stat_bin changed the way the bounds of the successive bins are included/excluded. And indeed there is this in the commit log:
commit bb4ec84bbedadd95647760fe586f64d0d6216abb
Author: hadley <h.wi...@gmail.com>
Date: Wed Dec 21 08:12:24 2011 -0600
Default to right-open, left-closed intervals in hist (Fixes #194)
So I checked :
library("devtools")
# install old version of plyr, compatible with the old ggplot2
install_github("plyr", branch="plyr-1.6")
# install previous commit
install_github("ggplot2", branch="1bfbee0fc791de8bfef901c156ebd04c4765b194")
library("ggplot2")
ggplot(diamonds, aes(carat, ..density..)) + geom_histogram(binwidth = 0.2) + facet_grid(.~cut)
# install suspected commit
install_github("ggplot2", branch="bb4ec84bbedadd95647760fe586f64d0d6216abb")
ggplot(diamonds, aes(carat, ..density..)) + geom_histogram(binwidth = 0.2) + facet_grid(.~cut)
and indeed, this commits changes the aspect of the histogram. It fixes a bug (nº 194 as mentionned in the commit message).
However, one thing that might be considered a drawback is that geom_histogram is now different from base::hist even when the breaks are the same:
d <- diamonds[diamonds$cut=="Fair",]
install_github("ggplot2", branch="1bfbee0fc791de8bfef901c156ebd04c4765b194")
ggplot(d, aes(carat)) + geom_histogram(binwidth = 0.2)
hist(d$carat, breaks=ggplot2:::fullseq(range(d$carat), size=0.2, pad=TRUE), freq=TRUE)
# -> same plot
ggplot(d, aes(carat, ..density..)) + geom_histogram(binwidth = 0.2)
hist(d$carat, breaks=ggplot2:::fullseq(range(d$carat), size=0.2, pad=TRUE), freq=FALSE)
# -> same plot
install_github("ggplot2", branch="bb4ec84bbedadd95647760fe586f64d0d6216abb")
ggplot(d, aes(carat)) + geom_histogram(binwidth = 0.2)
hist(d$carat, breaks=ggplot2:::fullseq(range(d$carat), size=0.2, pad=TRUE), freq=TRUE)
# -> different plot
Is this worth a "bug" report?
NB: after all this, if you don't want to be stuck in the past, redo
install.packages(c("plyr", "ggplot2"))
and start a new R session.
Jean-Olivier Irisson
---
Observatoire Océanologique
Station Zoologique, B.P. 28, Chemin du Lazaret
06230 Villefranche-sur-Mer
Tel: +33 04 93 76 38 04
Mob: +33 06 21 05 19 90
http://jo.irisson.com/
It does and the commit that I highlighted in the previous email basically changes right from TRUE to FALSE. What I am saying is that it might be better to default to what hist() does, to emphasize the fact that ggplot is a (better!) alternative to the regular plotting system of R.
If people get a different result for something as simple as an histogram, they might start to question the validity of gglot (even though both plots are mathematically valid and just use a different point of view). There was a similar debate a few months ago regarding qqnorm and stat_qq and it closed by basing the behaviour of stat_qq on qqnorm I think. And indeed the results are now the same:
set.seed(123)
x <- rnorm(15)
qqnorm(x)
library("ggplot2")
qplot(sample=x)