Skip to content
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

Contours fail with options(OutDec= ",") #5555

Closed
eliocamp opened this issue Dec 1, 2023 · 3 comments · Fixed by #5556
Closed

Contours fail with options(OutDec= ",") #5555

eliocamp opened this issue Dec 1, 2023 · 3 comments · Fixed by #5556

Comments

@eliocamp
Copy link
Contributor

eliocamp commented Dec 1, 2023

This probably hast o do with how ggplot2 is deriving the level variable from isoband's names.

Reprex:

library(ggplot2)

options(OutDec= ".")
ggplot(faithfuld, aes(waiting, eruptions, z = density)) +
  geom_contour_filled()

ggplot(faithfuld, aes(waiting, eruptions, z = density)) +
  geom_contour(aes(color = after_stat(factor(level))))

options(OutDec= ",")
ggplot(faithfuld, aes(waiting, eruptions, z = density)) +
  geom_contour_filled()
#> Warning in pretty_isoband_levels(names(isobands)): NAs introduced by coercion

#> Warning in pretty_isoband_levels(names(isobands)): NAs introduced by coercion
#> Warning: Computation failed in `stat_contour_filled()`
#> Caused by error in `levels<-`:
#> ! factor level [3] is duplicated

ggplot(faithfuld, aes(waiting, eruptions, z = density)) +
  geom_contour(aes(color = after_stat(factor(level))))
#> Warning in compute_group(...): NAs introduced by coercion
#> Warning in min(x): no non-missing arguments to min; returning Inf
#> Warning in max(x): no non-missing arguments to max; returning -Inf
#> Error: Must request at least one colour from a hue palette.

Created on 2023-12-01 with reprex v2.0.2

@teunbrand
Copy link
Collaborator

teunbrand commented Dec 1, 2023

Thanks for the report Elio! Can confirm this on my end.
I think it might just be a matter of adding withr::local_options(list(OutDec = ".")) to xyz_to_isobands().
The lower and upper interval are re-formatted elsewhere, so it should preserve , as decimal separator for display purposes.

@eliocamp
Copy link
Contributor Author

eliocamp commented Dec 1, 2023

Ah, good catch. I was trying hacky gsub stuff. I think it's withr::with_options() , though. I can submit a PR.

@teunbrand
Copy link
Collaborator

A PR would be welcome 🙏 ! The local_options() applies to the current evaluation environment (i.e. the xyz_to_isobands() function), whereas with_options() applies to the code executed in the code argument. Both should work in this case.

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 a pull request may close this issue.

2 participants