79118073

Date: 2024-10-23 13:22:00
Score: 0.5
Natty:
Report link

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("")))

graph

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"))
)

example from scales documentation

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Steven314