You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
awkward behavior from scale_fill_viridis_c(trans = "log") #4185
Log transformation of zero values for a continuous fill produces a warning about infinite values in a discrete y axis. This warning could be more clearly worded since the fill is neither discrete nor a y axis. There also appears to be differentiation of NaN from -Inf, leading to a cryptic NaN warning from negative fill values.
There doesn't appear to be any way to tell ggplot these fill values are expected in order to suppress the warnings. The closest I can see is something like scale_fill_viridis_c(na.value = "transparent", trans = "log"), which plots fine since apparently -Inf, NaN, and NA are treated interchangeably but is orthogonal to warning generation.
The resulting labels on the fill colorbar include 8+ decimal places, which is a curiously verbose default, though format_format(digits = n) provides a simple mitigation.
Some of the issues you are getting are related to what happens when you take logarithms of non-positive numbers.
seq(-1, 1, by=0.5)
#> [1] -1.0 -0.5 0.0 0.5 1.0
log(seq(-1, 1, by=0.5))
#> Warning in log(seq(-1, 1, by = 0.5)): NaNs produced#> [1] NaN NaN -Inf -0.6931472 0.0000000
The NaN's appear because logarithms for negative numbers are undefined. NaN is generally treated differently than NA.
We are getting infinite values after transformation since log(0) = -Inf.
It think an alternative might be to consider to use the inherits(scale, "ScaleContinuous") pattern above (which should be TRUE for both position and non-position continuous scales, but not for binned or discrete scales), but the scale itself is not passed as an argument.
In general, you have to be prepared for self$aesthetics to be a vector of multiple aesthetics that you all have to consider. So any code of the form self$aesthetics[1] makes me uncomfortable. There may be places where it's fine, but it can also go spectacularly wrong.
Activity
EmilHvitfeldt commentedon Aug 30, 2020
Some of the issues you are getting are related to what happens when you take logarithms of non-positive numbers.
The NaN's appear because logarithms for negative numbers are undefined. NaN is generally treated differently than NA.
We are getting infinite values after transformation since
log(0) = -Inf.teunbrand commentedon Nov 9, 2021
I also ran into this and I think these lines are responsible:
ggplot2/R/scale-.r
Lines 597 to 598 in aaaec2f
Which is fine for position scales, but generates these awkward messages for other types of scales.
I'm not sure how safe this is, but it might be possible to replace the first line in the chunk above by
At least, that is how
ggplot2:::guide_train.axis()retrieves the aesthetic from scales if not explicitly given as argument.In a similar vein,
ggplot2:::check_transformation()only considers the names of position scales for generating the message itself:ggplot2/R/scale-.r
Lines 1185 to 1191 in aaaec2f
It think an alternative might be to consider to use the
inherits(scale, "ScaleContinuous")pattern above (which should beTRUEfor both position and non-position continuous scales, but not for binned or discrete scales), but the scale itself is not passed as an argument.clauswilke commentedon Nov 9, 2021
In general, you have to be prepared for
self$aestheticsto be a vector of multiple aesthetics that you all have to consider. So any code of the formself$aesthetics[1]makes me uncomfortable. There may be places where it's fine, but it can also go spectacularly wrong.