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?
I wanted to make
geom_vline()adopt the theme's accent colour. Below was my sequence of attempts:Created on 2026-04-03 with reprex v2.1.1
The first is obviously wrong because
from_theme()only works insideaes(). 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 likefrom_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?