# Example with a custom reducer function for Bin

**URL:** <https://talk.observablehq.com/t/example-with-a-custom-reducer-function-for-bin/8641>\
**Category:** Help\
**Created:** [December 22, 2023, 12:30pm UTC](https://talk.observablehq.com/t/example-with-a-custom-reducer-function-for-bin/8641 "2023-12-22T12:30:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![matvil](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/matvil/32/7356_2.png) [@matvil](https://talk.observablehq.com/u/matvil)\
**Post date:** [December 22, 2023, 12:30pm UTC](https://talk.observablehq.com/t/example-with-a-custom-reducer-function-for-bin/8641/1 "2023-12-22T12:30:27Z")

</div>

I want to plot a histogram with a custom reducer function in `Plot.binX` instead of the predefined count etc. It is possible according to the docs:

_In addition, a reducer may be specified as:_  
_- a function to be passed the array of values for each bin and the extent of the bin_

but I am unable to make it work. Is there an example somewhere of this?

Thanks!

---

<div class="post-metadata">

**Author:** ![mcmcclur](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mcmcclur/32/2364_2.png) [@mcmcclur](https://talk.observablehq.com/u/mcmcclur)\
**Post date:** [December 22, 2023, 1:23pm UTC](https://talk.observablehq.com/t/example-with-a-custom-reducer-function-for-bin/8641/2 "2023-12-22T13:23:52Z")

</div>

Here’s an example where I use a custom reducer to normalize the of the rectangles so that the total area is equal to one:

> **[Normalized histogram](https://observablehq.com/d/0158051e7985f87b)**

---

<div class="post-metadata">

**Author:** ![matvil](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/matvil/32/7356_2.png) [@matvil](https://talk.observablehq.com/u/matvil)\
**Post date:** [December 22, 2023, 1:26pm UTC](https://talk.observablehq.com/t/example-with-a-custom-reducer-function-for-bin/8641/3 "2023-12-22T13:26:27Z")

</div>

Thanks! I was close, but not quite there. This solves it, and is close to my actual use case.
