# Using binX (using the mean reducer) with line plot

**URL:** <https://talk.observablehq.com/t/using-binx-using-the-mean-reducer-with-line-plot/7388>\
**Category:** Help\
**Created:** [December 6, 2022, 6:45pm UTC](https://talk.observablehq.com/t/using-binx-using-the-mean-reducer-with-line-plot/7388 "2022-12-06T18:45:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![octoscoob](https://avatars.discourse-cdn.com/v4/letter/o/ecae2f/32.png) [@octoscoob](https://talk.observablehq.com/u/octoscoob)\
**Post date:** [December 6, 2022, 6:45pm UTC](https://talk.observablehq.com/t/using-binx-using-the-mean-reducer-with-line-plot/7388/1 "2022-12-06T18:45:41Z")

</div>

I’m experimenting with Bin Transform and line graphs and have a dataset that looks like this:

```auto
data = [
{year: 2000, weight: 3, number: 3},
{year: 2000, weight: 7, number: 7},
{year: 2000, weight: 7, number: 4.3},
{year: 2000, weight: 8, number: 9},
{year: 2000, weight: 8, number: 9.1},
{year: 2000, weight: 9, number: 6},
{year: 2000, weight: 9, number: 6},
{year: 2000, weight: 10, number: 5.1},
{year: 2000, weight: 10, number: 8.24},
{year: 2000, weight: 11, number: 2},
{year: 2000, weight: 11, number: 1},
{year: 2001, weight: 3, number: 5},
{year: 2001, weight: 7, number: 7},
{year: 2001, weight: 7, number: 7},
{year: 2001, weight: 8, number: 7},
{year: 2001, weight: 8, number: 4},
{year: 2001, weight: 9, number: 2},
{year: 2001, weight: 9, number: 4},
{year: 2001, weight: 10, number: 3},
{year: 2001, weight: 10, number: 8},
{year: 2001, weight: 11, number: 9},
{year: 2001, weight: 11, number: 4},
{year: 2001, weight: 16, number: 7.5},
]

```

What I would like to create is a line graph with the x axis = weight, the y axis = number, and z is year, but I would like to get the average number when the weight is the same for the year. Is this possible with binX? This is what I have tried with little success.

```auto
Plot.plot({
  width: 1000,
  marks: [
    Plot.lineY(
      data,
      Plot.binX({ y: "mean" }, { x: "weight", z: "year" })
    )
  ]
})

```

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [December 6, 2022, 7:21pm UTC](https://talk.observablehq.com/t/using-binx-using-the-mean-reducer-with-line-plot/7388/2 "2022-12-06T19:21:21Z")

</div>

Looks like you’re just missing the `y: "number"` for the line to tell the bin transform what values to reduce.

 ![untitled (72)](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/2/2493195e58fa70fb0e47da04d29648aa6d175b83.png)

```nohighlight
Plot.plot({
  marks: [
    Plot.lineY(data, Plot.binX({ y: "mean" }, { x: "weight", y: "number", z: "year" }))
  ]
})

```

[https://observablehq.com/d/29ddba1365891c01](https://observablehq.com/d/29ddba1365891c01)
