-
Notifications
You must be signed in to change notification settings - Fork 2k
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
geom_contour
documentation is misleading
#4324
Comments
As I said in #4320, the true condition is that you have a matrix of z values whose locations can be identified with marginal vectors of x and y values. It's Ok for some z values to be missing, though, as long as there are corresponding I agree the documentation should spell this out clearly. |
I think your description is too strict. For example, this works: # First, start with a complete grid
df <- expand.grid(x=1:10, y=1:10)
df$z <- with(df, x^2 + y^2)
# Take the subset of lower z values
df <- subset(df, z < 100)
# Shuffle it
df <- df[sample(nrow(df)),]
head(df)
#> x y z
#> 37 7 4 65
#> 42 2 5 29
#> 52 2 6 40
#> 34 4 4 32
#> 7 7 1 50
#> 1 1 1 2
library(ggplot2)
ggplot(df, aes(x, y, z=z)) + geom_contour() Created on 2021-01-24 by the reprex package (v0.3.0) |
I'm pretty sure what's happening is that ggplot2 expands this input into a matrix of z values whose locations can be identified with marginal vectors of x and y values, replacing missing values with This also explains what happens with the rotated input data: ggplot2 turns it into a grid of all possible combinations of x and y, inserting |
Yes, that's what happens; I was just quibbling about your original description of it. The description in your most recent comment seems accurate, but is still incomplete: it covers the creation of the And there's still the issue of deciding on the balance between clarity and exact detailed correctness in the docs. |
For any square in the grid, if there's at least one point that has a z value of library(isoband)
m <- matrix(
c(NA, NA, NA, 0, 0, 0,
NA, NA, NA, 1, 1, 0,
0, 0, 1, 1, 1, 0,
0, 1, 1, 0, 0, 0,
0, 0, 0, 1, 0, 0,
0, 0, 0, 0, 0, 0),
6, 6, byrow = TRUE
)
plot_iso(m, 0.5, 1.5) Created on 2021-01-24 by the reprex package (v0.3.0) |
Okay, so how about this text to replace the current Description section:
|
I think this is good, except at the very end I'd write "using the Do you want to prepare a PR? |
Sure, I'll put in a PR, but I'd like to include an example using |
That's a question for @thomasp85. |
@cneyens: Thanks! I've used |
The documentation for
geom_contour
says:but in fact, as issue #4320 and its discussion describes, there are much more stringent requirements. Exactly what the requirements are is a little unclear to me; the code to do it is in
isoband_z_matrix()
here:ggplot2/R/stat-contour.r
Line 224 in 9741da5
(x, y)
pairs to be a large subset of the grid of all possible pairs of unique values ofx
andy
, with no repeats."It would also be helpful to add an example using
akima::interp()
, the usual way to produce the grid of values from irregular data.The text was updated successfully, but these errors were encountered: