dbplot icon indicating copy to clipboard operation
dbplot copied to clipboard

dbplot_histogram resulting in empty plots + proper histograms

Open RonaldVisser opened this issue 4 years ago • 3 comments

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!

RonaldVisser avatar Apr 28 '20 18:04 RonaldVisser

Thanks for opening this @RonaldVisser; same thoughts here. Hence, created PR #32.

Since dbplot_histogram()already usedb_compute_binsinternally, it includes the logic fromdb_binto auto-compute binwidth when it's leftNULL`.

leungi avatar Jun 01 '20 00:06 leungi

@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 avatar Sep 02 '20 23:09 jarodmeng

@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.

leungi avatar Sep 11 '20 23:09 leungi