Calculate hjust/vjust to align labels to the end of bars in ggplot2

bar_just(x, pivot = 0.5)

Arguments

x

numeric

pivot

numeric

Value

hjust or vjust

Examples

library(ggplot2)
mtcars |>
tibble::rownames_to_column() |>
ggplot(aes(y = reorder(rowname, mpg), x = mpg, label = mpg)) +
geom_col(fill = "deepskyblue") +
geom_text(aes(hjust = bar_just(mpg)))