# Legend options in Plot.plot?

**URL:** <https://talk.observablehq.com/t/legend-options-in-plot-plot/7164>\
**Category:** Help\
**Created:** [October 18, 2022, 3:33am UTC](https://talk.observablehq.com/t/legend-options-in-plot-plot/7164 "2022-10-18T03:33:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![akrawitz](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/akrawitz/32/4375_2.png) [@akrawitz](https://talk.observablehq.com/u/akrawitz)\
**Post date:** [October 18, 2022, 3:33am UTC](https://talk.observablehq.com/t/legend-options-in-plot-plot/7164/1 "2022-10-18T03:33:40Z")

</div>

How do I add legend options in a call to Plot.plot?

For example, I can do this:

```auto
data = FileAttachment("penguins.csv").csv({typed: true})`

```

and then this:

```auto
plot = Plot.plot({
  inset: 8,
  grid: true,
  color: {
    legend: "ramp",
  },
  marks: [
    Plot.dot(data, {x: "flipper_length_mm", y: "body_mass_g", stroke: "sex"})
  ]
})

```

And I can do this:

```auto
  plot.legend("color", {legend: "ramp", label: "Sex", width: 400})

```

But how do I get those legend options, `{legend: "ramp", label: "Sex", width: 400}`, into the initial plot?

Example notebook here: [https://observablehq.com/d/548adf32637ea5d3](https://observablehq.com/d/548adf32637ea5d3)

---

<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:** [October 18, 2022, 4:44am UTC](https://talk.observablehq.com/t/legend-options-in-plot-plot/7164/2 "2022-10-18T04:44:02Z")

</div>

Add it to the _color_ scale options like so:

```nohighlight
plot = Plot.plot({
  inset: 8,
  grid: true,
  color: {
    legend: "ramp",
    label: "Sex",
    width: 400
  },
  marks: [
    Plot.dot(data, { x: "flipper_length_mm", y: "body_mass_g", stroke: "sex" })
  ]
})

```

---

<div class="post-metadata">

**Author:** ![akrawitz](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/akrawitz/32/4375_2.png) [@akrawitz](https://talk.observablehq.com/u/akrawitz)\
**Post date:** [October 19, 2022, 4:22pm UTC](https://talk.observablehq.com/t/legend-options-in-plot-plot/7164/3 "2022-10-19T16:22:12Z")

</div>

Thanks - that works a charm.

I would suggest adding that to the docs - I couldn’t find it either on the Legends page:

> **[Legends / Observable Plot](https://observablehq.com/@observablehq/plot-legends?collection=@observablehq%2Fplot)**
>
> Axes and legends are a key component of any chart: they help the reader to understand how the abstract dimensions of the data have been encoded as visual variables, and allow them to interpret the value of a given mark. Plot will generate a legend...

or on the Scales page:

> **[Scales / Observable Plot](https://observablehq.com/@observablehq/plot-scales?collection=@observablehq%2Fplot)**
>
> Scales map an abstract value such as time or temperature to a visual value such as x- or y-position or color. Scales define a plot’s coordinate system. In Plot, scales are named: x or y for position; fx or fy for facet position; r for radius; or...

and it wasn’t obvious, at least to me, that adding a `width` parameter to the `scale` would apply to the `legend` for that scale as opposed to somehow affecting to the scale itself.
