geom_label
does not work as expected with a stat of "summary".
Instead, you have to use after_stat
, which seems inconsistent with the grammar in how the x and y aesthetics are treated where you don't do this.
Could geom_label
with a stat of "summary" work with label aesthetic variable?
library(tidyverse)
library(tidyplots)
#doesn't
spendings |>
ggplot(aes(y = category, x = amount, label = amount)) +
geom_bar(stat = "summary", fun = \(x) sum(x)) +
geom_label(stat = "summary", fun = \(x) sum(x))
#> Warning: Removed 5 rows containing missing values or values outside the scale range
#> (`geom_label()`).

#works
spendings |>
ggplot(aes(y = category, x = amount, label = after_stat(x))) +
geom_bar(stat = "summary", fun = \(x) sum(x)) +
geom_label(stat = "summary", fun = \(x) sum(x))

Created on 2025-05-21 with reprex v2.1.1