-
Notifications
You must be signed in to change notification settings - Fork 2.1k
calculate z.range in stat_contour and stat_contour_filled on the full layer data #3883
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
Conversation
I think this breaks the use of Lines 71 to 80 in 435ac04
We don't know the overall z range of inferred densities until we have inferred them for all groups. Does the following reprex work with your branch? library(ggplot2)
set.seed(4393)
dsmall <- diamonds[sample(nrow(diamonds), 1000), ]
ggplot(dsmall, aes(x, y)) +
geom_density_2d(aes(colour = after_stat(level))) +
facet_grid(. ~ cut) Created on 2020-03-10 by the reprex package (v0.3.0) |
Continuing discussion from here: #3875 (comment)
Just to be clear: I think we should return both. So this is primarily a discussion about what the default mapping for Also, unless I'm missing something, it's fairly easy to go from the numeric limits to the ordered factor. It's much harder the other way round, because we don't have a simple inverse to library(ggplot2)
library(glue)
set.seed(4393)
dsmall <- diamonds[sample(nrow(diamonds), 1000), ]
ggplot(dsmall, aes(x, y)) +
geom_density_2d_filled(aes(fill = after_stat(bin))) +
scale_fill_viridis_d(name = NULL)
ggplot(dsmall, aes(x, y)) +
geom_density_2d_filled(
aes(fill = after_stat(ordered(glue("({level_low}, {level_high}]"))))
) +
scale_fill_viridis_d(name = NULL) Created on 2020-03-10 by the reprex package (v0.3.0) |
I just realized that there may be a clean way to resolve all of these issues at the same time. Let me give it a shot. |
Well, if you return You are correct that your example with density_2d doesn't work with this PR. I'm sure that is fixable, but I'll let you work on your solution for now |
The latest iteration of my PR #3864 now incorporates the approach you proposed here and fixes all associated issues. See example below. Could you take a look and let me know whether I'm on the right track? If yes I'll clean up the code and rewrite the documentation. library(ggplot2)
ggplot(faithfuld, aes(waiting, eruptions, z = density)) +
geom_contour_filled() +
facet_wrap(~waiting < 70) set.seed(4393)
dsmall <- diamonds[sample(nrow(diamonds), 1000), ]
d <- ggplot(dsmall, aes(x, y))
d + geom_density_2d_filled() +
facet_wrap(~cut) d + geom_density_2d_filled(contour_var = "ndensity") +
facet_wrap(~cut) d + geom_density_2d_filled(contour_var = "count") +
facet_wrap(~cut) d + geom_density_2d(aes(color = after_stat(level))) +
facet_wrap(~cut) d + geom_density_2d(aes(color = after_stat(level)), contour_var = "ndensity") +
facet_wrap(~cut) d + geom_density_2d(aes(color = after_stat(level)), contour_var = "count") +
facet_wrap(~cut)
#> Warning: stat_contour(): Zero contours were generated
#> Warning in min(x): no non-missing arguments to min; returning Inf
#> Warning in max(x): no non-missing arguments to max; returning -Inf Created on 2020-03-11 by the reprex package (v0.3.0) |
The key idea of my revised approach is to implement a true chaining of the 2d-density stat and the contour stat, by reimplementing |
Closing this now. All in all we are on the same page and I'm happy with #3864 |
Fixes #3875
This PR fixes the issue as discussed in the thread. The issue is also present in the standard
stat_contour
where the levels of the contour lines would not be equivalent across panelsOld buggy behaviour
Created on 2020-03-10 by the reprex package (v0.3.0.9001)
Working example with PR
Created on 2020-03-10 by the reprex package (v0.3.0.9001)