tidyverse / tidyverse/ggplot2

`geom_vline()` and friends cannot use `mapping` when `xintercept` is set

Open
#6,831 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

layers :chart_with_upwards_trend:
Dominant language
R
Stars
7k
Forks
2.1k
Avg merge
59m
Merged PRs (30d)
2

Description

I wanted to make geom_vline() adopt the theme's accent colour. Below was my sequence of attempts:

library(ggplot2)

ggplot() + geom_vline(xintercept = 0, colour = from_theme(accent))
#> Error:
#> ! object 'accent' not found
ggplot() + geom_vline(aes(colour = from_theme(accent)), xintercept = 0)
#> Warning: `geom_vline()`: Ignoring `mapping` because `xintercept` was provided.

ggplot() + geom_vline(aes(xintercept = 0, colour = from_theme(accent)))

Created on 2026-04-03 with reprex v2.1.1

The first is obviously wrong because from_theme() only works inside aes(). The second seems like it should work, but the geoms are being too strict.

In the past I understand why it might have been discouraged to use mapping, but I think with the newer features like from_theme() the situation changed a bit and the limitation seems unnecessary.

Would it be worth making geom_vline(aes(colour = from_theme(accent)), xintercept = 0) work?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the geom_vline() implementation and trace how it handles mapping when xintercept is supplied, including the related geoms mentioned in the issue. Confirm the behavior with the provided from_theme(accent) example; done means mapping is accepted alongside xintercept without the warning and the line uses the theme accent colour.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.