Plots: How to create a histogram such that sum of bar heights =1

Great, that was my suggestion 1 here Plots: How to create a histogram such that sum of bar heights =1 - #15 by mkborregaard
I prefer this workaround.

Two more plugs for more flexible normalization options within histogram. (And I know these are not the world’s strongest arguments, but …)

  1. Matlab does it. ‘Normalization’ with a valid option (‘count’, ‘probability’, ‘countdensity’, ‘pdf’, ‘cumcount’, or ‘cdf’)
  2. Wikipedia says it’s fine. “A histogram may also be normalized to display “relative” frequencies. It then shows the proportion of cases that fall into each of several categories, with the sum of the heights equaling 1.
    However, bins need not be of equal width; in that case, the erected rectangle is defined to have its area proportional to the frequency of cases in the bin. The vertical axis is then not the frequency but frequency density — the number of cases per unit of the variable on the horizontal axis.”

Hey, the best place to make those arguments would be on the open StatsBase PR.

UPDATE: The StatsBase PR got merged, which means that from the next release (or on StatsBase master), you can now simply plot this type of histogram with Plots using histogram([6,6,6,6,7,7,7,7,7,8], normalize = :probability).

Welcome to the wonderful world of Open Source development, @Seth_Chandler :slight_smile:

7 Likes