Skip to content

Allows breaks to be a function in geom_contour() #4652

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

Merged
merged 3 commits into from
Nov 9, 2021

Conversation

eliocamp
Copy link
Contributor

This is a refreshed version of #2320

library(ggplot2)

v <- ggplot(faithfuld, aes(waiting, eruptions, z = density))
v + geom_contour(binwidth = 0.001)

my_breaks <- function(range, binwidth) {
  b <- scales::fullseq(range, binwidth)
  b[b != 0.002]  # remove the 0.002 contour
}

v + geom_contour(breaks = my_breaks, binwidth = 0.001)

Created on 2021-10-28 by the reprex package (v2.0.0)

@thomasp85
Copy link
Member

Thanks - can I get you to update it so that a lambda function can be supplied in line with (what a aspire to) do with other arguments of this type?

@eliocamp
Copy link
Contributor Author

Ah, yes. That's be something like breaks = ~ fullseq(.x, .y)?

@thomasp85
Copy link
Member

Yup - you can use the utility function here to convert the input argument:

ggplot2/R/scale-.r

Lines 1199 to 1201 in 759c63c

allow_lambda <- function(x) {
if (is_formula(x)) as_function(x) else x
}

@eliocamp
Copy link
Contributor Author

There.

@thomasp85
Copy link
Member

great - can you add a bullet to NEWS?

@thomasp85 thomasp85 merged commit 4c1c8df into tidyverse:main Nov 9, 2021
@thomasp85
Copy link
Member

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants