Why does suppressMessages not suppress the geom_histogram bins message?

library(tidyverse)
#> Warning: package 'ggplot2' was built under R version 4.3.1
#> Warning: package 'purrr' was built under R version 4.3.1
#> Warning: package 'dplyr' was built under R version 4.3.1
#> Warning: package 'lubridate' was built under R version 4.3.1
library(palmerpenguins)

p <- penguins |>
  tidyr::drop_na(sex) |>
  ggplot() +
  geom_histogram(aes(x = flipper_length_mm), stat = "bin")

suppressMessages(p)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Created on 2023-10-08 with reprex v2.0.2

library(ggplot2)
library(palmerpenguins)
p <- penguins |>
  tidyr::drop_na(sex) |>
  ggplot(aes(x = flipper_length_mm)) +
  geom_histogram(binwidth = 5)
p

image

Per the help page, the message is didactic, because

The [binwidth] default is to use the number of bins in bins [which is NULL], covering the range of the data. You should always override this value, exploring multiple widths to find the best to illustrate the stories in your data.

1 Like

Is there anyway to turn it off in a non-global way?

Can't come up with a setting that would turn it off without creating a custom stat_bin and omitting

    if (is.null(params$breaks) && is.null(params$binwidth) && is.null(params$bins)) {
      cli::cli_inform("{.fn {snake_class(self)}} using {.code bins = 30}. Pick better value with {.arg binwidth}.")
      params$bins <- 30
    }

params appears to be defined locally, so can't be over-ridden globally.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.