Closed vincentarelbundock closed 7 months ago
Howdy @vincentarelbundock ! I use an estimator for binwidth to give decent binwidth options, as taken from Rob Hyndman.
bw <- 2 * stats::IQR(no_na, na.rm = TRUE) / length(data_in)^(1 / 3)
In the case of the data you have provided:
stats::IQR(dat$hist_data[[1]], na.rm = TRUE)
#> [1] 0
So the binwidth is reporting a 0. I can get around that by hard-coding the bw
like so:
gt(dat) |> gtExtras::gt_plt_dist(hist_data, type = "histogram", bw = 1)
I'm going to re-open, as I think I have a solution for bw <= 0
as seen in #104
# conditional to switch between estimated binwidth or Freedman–Diaconis rule
{
if(bw > 0){
geom_histogram(color = "white", fill = "#f8bb87", binwidth = bw)
} else {
hist_breaks <- hist(col[!is.na(col)], breaks = "FD")$breaks
geom_histogram(color = "white", fill = "#f8bb87", breaks = hist_breaks)
}
} +
This is likely closed by: https://github.com/jthomasmock/gtExtras/commit/639d68ab9c61f6a35d7ce91a9d5a084468fb8470
Hi, thanks for a great package!
I get a warning and an error when trying to draw a histogram for a binary variable, and I can’t figure out what the problem is. I’d be very grateful if you could give me a hint. Minimal example:
The data look fine to me:
Initially reported here:
https://github.com/vincentarelbundock/modelsummary/issues/680