# How to access an aggregated value in Plot?

**URL:** <https://talk.observablehq.com/t/how-to-access-an-aggregated-value-in-plot/6962>\
**Category:** Help\
**Created:** [August 25, 2022, 2:47pm UTC](https://talk.observablehq.com/t/how-to-access-an-aggregated-value-in-plot/6962 "2022-08-25T14:47:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nachocab](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/nachocab/32/2426_2.png) [@nachocab](https://talk.observablehq.com/u/nachocab)\
**Post date:** [August 25, 2022, 2:47pm UTC](https://talk.observablehq.com/t/how-to-access-an-aggregated-value-in-plot/6962/1 "2022-08-25T14:47:36Z")

</div>

Let’s say I want to show the cumsum value in the `title` attribute in a plot that uses `Plot.map`, like this one:

> **[Map Transform / Observable Plot](https://observablehq.com/@observablehq/plot-map#cell-7)**
>
> The map transform groups data into series and then transforms each series’ values, say to normalize them relative to some basis or to apply a moving average. Like the group and bin transforms, the Plot.map transform takes two arguments: an outputs...

Is there something I can put here?

```auto
Plot.lineY(
  values,
  Plot.map(
    { y: "cumsum" },
    { 
        y: values,
        title: d => `The cumsum value is ${d.????}`
    },
  )
).plot();

```

---

<div class="post-metadata">

**Author:** ![Fil](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/fil/32/207_2.png) [@Fil](https://talk.observablehq.com/u/Fil)\
**Post date:** [August 25, 2022, 3:13pm UTC](https://talk.observablehq.com/t/how-to-access-an-aggregated-value-in-plot/6962/2 "2022-08-25T15:13:44Z")

</div>

sure! With two consecutive “maps”.

```auto
Plot.dot(
  values,
  Plot.map(
    { title: (cs) => Array.from(cs, (s) => `The cumsum value is ${s}`) },
    Plot.map(
      { title: "cumsum", y: "cumsum" },
      {
        x: d3.range(values.length),
        y: values,
        title: values
      }
    )
  )
).plot()

```

---

<div class="post-metadata">

**Author:** ![nachocab](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/nachocab/32/2426_2.png) [@nachocab](https://talk.observablehq.com/u/nachocab)\
**Post date:** [August 26, 2022, 8:42am UTC](https://talk.observablehq.com/t/how-to-access-an-aggregated-value-in-plot/6962/3 "2022-08-26T08:42:19Z")

</div>

Thanks!

I guess an alternative is to do the sum myself (or use `d3.cumsum`):

```auto
Plot.dot(
  values,
  Plot.map(
    {
      y: "cumsum",
      title: (v) => {
        let cumsum = 0;
        return v.map((d) => `The cumsum value is ${(cumsum += d)}`);
      },
    },
    {
      x: d3.range(values.length),
      y: values,
      title: values,
    }
  )
).plot();

```
