-
Notifications
You must be signed in to change notification settings - Fork 2.1k
contour fails when coordinates are not aligned with axes #4320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The requirement for contouring is not that you have a regularly spaced grid but that you have a matrix of z values whose locations can be identified with marginal vectors of x and y values. See here for a grid that is not regularly spaced: library(ggplot2)
df <- expand.grid(x = c(1, 2, 4, 8, 16, 32),
y = c(1, 2, 4, 8, 16, 32))
df$z <- c(volcano[53:58, 29:34]) # arbitrary
ggplot(df, aes(x = x, y = y)) +
geom_point() +
geom_contour(aes(z = z)) +
coord_fixed() Created on 2021-01-20 by the reprex package (v0.3.0) If your input data doesn't have this structure then you may have to force it into this structure via interpolation. |
(Having said this, it would probably be possible to add this feature to |
Relevant SO post with a fairly simple solution: https://stackoverflow.com/a/38177092/4975218 Requires an additional dependency on the akima package: https://cran.r-project.org/web/packages/akima/index.html |
Thanks! I'm aware of multiple SO posts where interpolation is offered as a solution for cases where the starting data set is not gridded, but I was under the impression that the requirement for
|
If you feel the documentation is not sufficiently clear, could you open a separate issue just about that? |
Below I have regularly spaced points that are not aligned with the plot axes. I want to plot contour lines but
geom_contour
seems to fail here. I vaguely remember this used to work in some former ggplot version, but I tried with versions 3.3.2 and 3.3.0 and those also don't plot contours for this data set so I might be wrong... I would expectgeom_contour
to be able to handle this since the points are fairly regularly spaced (disregarding minor rounding errors from the rotation calculation I've done here).For context: these could be spatial data points (XY coordinates) placed on a regular grid for which I've obtained several continuous variables, e.g. groundwater levels and chloride concentrations.
Created on 2021-01-20 by the reprex package (v0.3.0)
Session info
The text was updated successfully, but these errors were encountered: