# Plot: rule across different groups

**URL:** <https://talk.observablehq.com/t/plot-rule-across-different-groups/7631>\
**Category:** Help\
**Created:** [February 14, 2023, 10:47am UTC](https://talk.observablehq.com/t/plot-rule-across-different-groups/7631 "2023-02-14T10:47:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicola](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/nicola/32/1039_2.png) [@nicola](https://talk.observablehq.com/u/nicola)\
**Post date:** [February 14, 2023, 10:47am UTC](https://talk.observablehq.com/t/plot-rule-across-different-groups/7631/1 "2023-02-14T10:47:59Z")

</div>

I have several graphs in a single plot (like this one [Facets / Observable Plot / Observable | Observable](https://observablehq.com/@observablehq/plot-facets?collection=@observablehq/plot#cell-28)) and I wanted to make a single verticle red rule across graphs.

I can’t find documentation for something like this.

Is this possible?

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [February 14, 2023, 11:38am UTC](https://talk.observablehq.com/t/plot-rule-across-different-groups/7631/2 "2023-02-14T11:38:29Z")

</div>

Sounds like you’re looking for the rule mark:

```javascript
  marks: [
    // ...
    Plot.ruleX([35], {stroke: "red"})
  ]

```

> **[Rule Mark / Observable Plot](https://observablehq.com/@observablehq/plot-rule)**
>
> Rules are horizontal or vertical lines. A ruleY↔︎ has a y-value, while a ruleX↕︎ has an x-value. Rules are often used as annotations, say to mark the y = 0 baseline (in red below for emphasis) in a line chart. As annotations, rules often have...

---

<div class="post-metadata">

**Author:** ![nicola](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/nicola/32/1039_2.png) [@nicola](https://talk.observablehq.com/u/nicola)\
**Post date:** [February 14, 2023, 3:11pm UTC](https://talk.observablehq.com/t/plot-rule-across-different-groups/7631/3 "2023-02-14T15:11:43Z")

</div>

Unfortunately the rule mark will create a rule in each of the graph, while instead I would like to have a single rule!

---

<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:** [February 14, 2023, 6:30pm UTC](https://talk.observablehq.com/t/plot-rule-across-different-groups/7631/4 "2023-02-14T18:30:30Z")

</div>

If you just want it on a specific facet, you can specify that using the corresponding **fx** or **fy** option. For example, in the barley chart in the Plot: Facets notebook, if you just want a red rule at _x_ = 20 on the _Grand Rapids_ facet, you’d say:

```plaintext
Plot.ruleX([20], {stroke: "red", fy: ["Grand Rapids"]})

```

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [February 14, 2023, 8:43pm UTC](https://talk.observablehq.com/t/plot-rule-across-different-groups/7631/5 "2023-02-14T20:43:16Z")

</div>

Additionally you can remove the padding between facets to get the appearance of a single continuous line:

```javascript
  fy: { padding: 0 },

```

![image](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/1/15ad6f1bf88aab0eb289bc173a299338ec8b0546.png)

---

<div class="post-metadata">

**Author:** ![nicola](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/nicola/32/1039_2.png) [@nicola](https://talk.observablehq.com/u/nicola)\
**Post date:** [February 15, 2023, 9:37am UTC](https://talk.observablehq.com/t/plot-rule-across-different-groups/7631/6 "2023-02-15T09:37:58Z")

</div>

I want to achieve what mootari is showing, except that I the rule should go across graphs, the padding works, but I wonder if there is a better strategy.

Thank you!

---

<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:** [February 15, 2023, 10:00pm UTC](https://talk.observablehq.com/t/plot-rule-across-different-groups/7631/7 "2023-02-15T22:00:47Z")

</div>

There’s not currently a way to draw a single rule at a specific abstract _x_ value while connecting that rule across facets. Faceted marks are interrupted across facets, so you get multiple rules.

That said, you can make the rules appear as a single rule by turning off padding between facets as @mootari suggested, or by extending the rule using negative insets. (You’ll have to futz with the exact value of the negative inset if you don’t want adjacent rules to overlap.)

 ![Screenshot 2023-02-15 at 1.57.09 PM](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/2/26d4ba9f4ed0ee607648dc29a2638aa8439b54e5.png)

```plaintext
Plot.ruleX([35], {stroke: "red", inset: -7})

```

As an alternative strategy, you can use super faceting (`facet: "super"`) which does allow you to draw a single mark across facets. But in this case you are not allowed to use the _x_ or _y_ scales, so you must position the rule yourself in screen coordinates. This feature is typically used for axis labels or to draw plot frames. For example, here’s a red rule offset by 100px from the left edge of the frame:

 ![Screenshot 2023-02-15 at 1.59.24 PM](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/3/399854ff4142080ebd9da5df78705c3d09c1c4b8.png)

```plaintext
Plot.frame({anchor: "left", dx: 100, stroke: "red", facet: "super"})

```

---

<div class="post-metadata">

**Author:** ![nicola](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/nicola/32/1039_2.png) [@nicola](https://talk.observablehq.com/u/nicola)\
**Post date:** [February 17, 2023, 10:08am UTC](https://talk.observablehq.com/t/plot-rule-across-different-groups/7631/8 "2023-02-17T10:08:32Z")

</div>

Thank you, brilliant!
