Color expansion of `geom_contour_filled`
Dear ggplot2 developer,
I was browsing the official documentation of geom_contour_filled (https://ggplot2.tidyverse.org/reference/geom_contour.html), and wonder if it would be possible to add a expand parameter (similar to what we did in scale_x_continous) that can be used to expand the colored region outwards. This might be helpful in situation where the contour data only capture a part of the full spectrum (the rest part are with low frequency/level, likely not presented in observed data, but they are still important to display on the figure)
Specifically, in the documentation example
Thanks, Wenbin
Hi Wenbin,
If the input data is a grid of values, as is the case for geom_contour_filled(), I think the correct approach would be to ensure that the relevant values are present in the input data. If the input data are individual x/y observations, the geom_density_2d() function can compute density values outside the bounds of the input data. I don't think it makes sense to extrapolate in the case of geom_contour_filled(), but it is fine to compute density in geom_density_2d().
For geom_density_2d(), you can just use the x-scale limits to expand the region:
library(ggplot2)
ggplot(faithful, aes(waiting, eruptions)) +
geom_density2d_filled(n = 75, h = c(10, 1)) +
xlim(NA, 120)

Created on 2023-12-11 with reprex v2.0.2
I'm closing this issue as there appears to be a reasonable path to the desired outcome without the need for changing anything in ggplot2. If I have misunderstood the issue, please clarify and we can reopen the issue.