ggplot2 icon indicating copy to clipboard operation
ggplot2 copied to clipboard

geom_contour undefined behaviour for multiple observations per grid-point

Open jessexknight opened this issue 3 years ago • 0 comments

If there are multiple observations per grid point for geom_contour*, several aspects of behaviour are undefined. I was expecting the mean value for each unique grid point to be used in the contour, but it was not. It seems both the contours themselves and the computed bins/levels are affected.

library('ggplot2')
M = pracma::meshgrid(seq(0,1,l=10))
X1 = data.frame(x=c(M$X),y=c(M$Y),z=c(M$X * M$Y))
X2 = X1; X2$z = 0
X3 = X1; X3$z = -X1$z
plot.one = function(X.){ ggplot(X.,aes(x=x,y=y,z=z)) + geom_contour_filled() }
plot.one(X1)
plot.one(X2)
plot.one(X3)
plot.one(rbind(X1,X2))
plot.one(rbind(X1,X2,X3))
plot.one(rbind(X3,X2,X1))

I think the relevant code is here

I don't necessarily think the aggregation should be performed by geom_contour, but perhaps some explanation of how the data will be used can be added to the docs --- or even just a warning that the behaviour is undefined for multiple observations per grid-point.

jessexknight avatar Aug 07 '22 19:08 jessexknight