I'm getting a warning message I don't understand for simple bar charts in ggplot2
> df <- data.frame(X = 127:131, Y = rnorm(5))
> df
X Y
1 127 0.9391077
2 128 -0.9392529
3 129 -1.1296221
4 130 1.1454907
5 131 1.8564596
> ggplot(df) + geom_bar(aes(X,Y), stat ="identity", position = "dodge")
Warning message:
position_dodge requires constant width: output may be incorrect
It only seems to happen for certain ranges of X values. I've googled for info on this, but it all seems to be talking about cases when the widths genuinely are different, or cases where stat is not "identity". In this case the X values are just integers, so it should be simple.
The chart produced looks ok, so I'm uneasy about just ignoring a warning I don't understand.
Any idea what is going on?
Setting
options(warn = 2, error = recover)
, and rerunning the code lets us find the problem.Inside the
collide
function (number 16 in the call stack), there is this piece of code:Floating point rounding errors mean that
widths
takes slightly different values.The tolerance for checking that the numbers are the same is too strict: about 2.2e-14.
So the warning is erroneous; don't worry about it.