dbplot
dbplot copied to clipboard
dbplot_histogram resulting in empty plots + proper histograms
I enjoy using this library, but recently the histograms were not working as should. There were no bars for numeric values, only an empty graph. For integers there was no problem...
Solution: change line 92 in https://github.com/edgararuiz/dbplot/blob/master/R/histogram.R
92 (old) geom_col(aes(x, count)) + 92 (new) geom_col(aes(x, count), orientation="x", width = binwidth) +
This works as a charm when binwidths are known and it produces proper histograms at the same time, since there should be no gap between bars in a histogram! Although this does not work when the binwidth is not set, maybe the binwidth calculation from (https://github.com/edgararuiz/dbplot/blob/master/R/dbbin.R) could be included somehow?
Thanks in advance!
Thanks for opening this @RonaldVisser; same thoughts here. Hence, created PR #32.
Since dbplot_histogram
()already use
db_compute_binsinternally, it includes the logic from
db_binto auto-compute binwidth when it's left
NULL`.
@leungi A more general (and backwards compatible) solution is to bubble up the "orientation" argument to the "dbplot_histogram" function with a default value of NA. In this way, users who call the dbplot_histogram() function without the "orientation" argument will get exactly the same behavior, but users who prefer to set the orientation (most probably because the auto-detection of orientation fails) can set it in "dbplot_histogram" and it will get passed to the "geom_col()" call.
@jarodmeng : thanks for feedback; let's see how the pkg maintainers (e.g., @edgararuiz ) respond to this issue.
I can update my PR #32 as needed.