1

This plot is great. It has everything I need, and the y=0 value is in a sensible place despite the logarithmic scale. All is great!

library(ggplot2)
df <- data.frame(x=1:3, y=c(1, 0, 2))
print(ggplot(df, aes(x=x, y=y)) + geom_point() + scale_y_log10())

enter image description here

How can I suppress this warning, and only this warning?

Transformation introduced infinite values in continuous y-axis

bers
  • 4,817
  • 2
  • 40
  • 59
  • The log of 0 is negative infinity, so the warning is accurate. Why suppress it? – user2554330 Aug 21 '20 at 11:41
  • 1
    @user2554330 every warning is accurate. Why suppress any warning? Because expected, non-actionable warnings (especially in large numbers) may distract you such that you overlook unexpected, actionable warnings. – bers Aug 21 '20 at 11:43
  • You can use `suppressWarnings()` (just wrap your `print()` call in it) – duckmayr Aug 21 '20 at 11:45
  • @duckmayr "`suppressWarnings` evaluates its expression in a context that ignores **all warnings**." That's not what I want. "How can I suppress this warning, **and only this warning**?" – bers Aug 21 '20 at 12:00
  • @bers Very interesting wrinkle! Didn't think about that issue. Not sure, but I'll get back to you if I think of something – duckmayr Aug 21 '20 at 12:03
  • 1
    Does this answer your question? [Suppress any emission of a particular warning message](https://stackoverflow.com/questions/38603668/suppress-any-emission-of-a-particular-warning-message) You can find a more friendly version (imo) of the same approach [at this blog](http://romainfrancois.blog.free.fr/index.php?post/2009/05/20/Disable-specific-warnings) – duckmayr Aug 21 '20 at 12:06
  • @duckmayr I had expected a `ggplot2`-based solution, but I agree - in the way my question is asked, this would be a solution. – bers Aug 21 '20 at 12:19
  • 1
    If you have zero values, the log-transformation is clearly not appropriate. You should not suppress this warning. – Roland Aug 21 '20 at 12:22
  • @Roland thank you for your input. I doubt that you can assess if and why I should have zeros in my data, and whether the log transformation is appropriate or not. But let me tell you: in an exponential dilution series (concentrations 1:1, 1:10, 1:100, ...) with a single negative control that has 0 concentration, the output as shown above is very appropriate. – bers Aug 21 '20 at 12:25

1 Answers1

-1

you can handle it by out of bounds argument. Please find the code below.

 library(ggplot2)
df <- data.frame(x=1:3, y=c(1, 0, 2))
print(ggplot(df, aes(x=x, y=y)) + geom_point() + scale_y_log10(oob = scales::squish_infinite)

  
  • That moves the `y=0` point up, right? Sorry, I do not want that. Also, it still prints the warning. – bers Aug 21 '20 at 12:01