I am graphing a data set of many points in the x, y and z dimensions. For each x and y there can be multiple z's. What I am attempting to do is divide the xy-plane into a grid of 50x50 and then graph the maximum values of z for each box in a contour plot. I thought the code below that I found online worked but, upon closer inspection, it looks like it is dropping points or skewing the data. Is there something wrong with my code?
df<-eff[c("Xs",Ys","Zs")]
df$x<-cut(df$Xs, breaks=50, labels=FALSE)
df$y<-cut(df$Ys, breaks=50, labels=FALSE)
df.max<-expand.grid(x=1:50, y=1:50)
df.max<-merge(df.max, aggregate(Zs~x+y, df, max), all.x=TRUE)
z<-matrix(df.max$Zs, nr=50, nc=50)
x.values <- min(df$Xs)+(0:49)*diff(range(df$Xs))/50
y.values <- min(df$Ys)+(0:49)*diff(range(df$Ys))/50
image2D(x=x.values, y=y.values, z, rasterImage = TRUE, contour = list(lwd = 2, col = jet.col(11)),
main="Contour Plot", xlab="Xs",ylab="Ys", clab="Zs", ylim=c(0,max(df$Ys)*1.05),
xlim=c(0,max(df$Xs)*1.05))
According to the plot of just the xy-plane (which I believe is correct), the profile of the contour plot should look like this:
Notice that it intersects the y-axis around 90k and there is a minimum around (25k,73k).
My contour plot from the same data looks like this:
I do not have sample data to provide at the moment because my model is in the middle of running and I don't want to start it all over. I can add a sample later if necessary.
here is a link to the data