The scales package added a helper function that can provide SI prefixes and optionally add a unit.
From what I can tell, this was introduced in #339 (March 2022) and is documented here (see the scale_cut parameter).
Using the original example:
library(ggplot2)
library(scales)
data.frame(x = LETTERS[1:5], n = c(0, 5000, 10000, 15000, 20000)) |>
ggplot(aes(x, n)) +
geom_point() +
scale_y_continuous(labels = label_number(scale_cut = cut_si("")))
By changing the empty quotes inside cut_si(), you can append a unit such as "m" or "g".
Example from the documenation:
demo_log10(
c(1e-9, 1),
breaks = log_breaks(10),
labels = label_number(scale_cut = cut_si("g"))
)