1

I'm trying to make a contour surface in ggplot2, but as you can see the contour is limited to just the top left. What is going on here?

x<-c(1.4, 1.4, 1.05, 1.05, 0.875, 0.7, 0.35, 0.7, 1.4, 0.175, 0, 1.05, 0.175, 0.0875, 0, 0.0875, 0, 0.175, 0.7, 0.525, 0, 0.35, 0.35, 0.35, 0.7, 0.525, 0.0875, 0.175, 0, 0.0875, 0.35, 0.525, 1.4, 0.7, 0.0875, 1.4, 1.225, 0.175)
y<-c(0.2, 0.025, 0.15, 0.0375, 0.03125, 0.2, 0.2, 0.05, 0.4, 0.1, 0, 0.075, 0.4, 0.025, 0, 0.05, 0, 0.05, 0.025, 0.0375, 0, 0.4, 0.025, 0.05, 0.4, 0.15, 0.2, 0.025, 0, 0.4, 0.1, 0.075, 0.1, 0.1, 0.1, 0.05, 0.04375, 0.2)
z<-c(11.71, 10.65, 11.59, 6.75, 9.75, 9.64, 11.51, 10.99, 8.92, 9.6, 14.28, 7.02, 10.81, 10.13, 10.4, 8.87, 10.68, 6.28, 11.82, 10.59, 9.68, 7.54, 4.1, 7.77, 2.04, 10.91, 8.52, 16.35, 13.36, 5.78, 10.97, 11.15, 9.98, 7.57, 11.25, 6.15, 7.64, 10.18)

contourDF<-data.frame(x,y,z)

ggplot(data=contourDF, aes(x=x, y=y, z=z))+
  geom_contour_filled()+
  scale_x_continuous(trans='log2') +
  scale_y_continuous(trans='log2') +
  geom_point(aes(x=x, y=y, size=z),
             fill="white",
             color="black",
             shape=21,
             stroke=2)

enter image description here

ITM
  • 73
  • 9
  • 1
    It is because you don't have a rectangular grid - if you just use the points on the main 5x5 grid then it works OK. To use all points you will perhaps need to interpolate z on a finer grid before contouring. The `interp` package might help. – Andrew Gustar Feb 23 '21 at 16:03
  • 1
    Maybe related: [Plotting contours on an irregular grid](https://stackoverflow.com/questions/19339296/plotting-contours-on-an-irregular-grid) – Henrik Feb 23 '21 at 16:09
  • @Andrew Gustar is correct – ITM Feb 23 '21 at 16:15

1 Answers1

0

@Andrew Gustar is correct. The contour will fill the space when I provide just a rectangular grid.

ITM
  • 73
  • 9