Skip to content

label_comma(scale_cut = cut_short_scale()) creates misleading rounding of labels #517

@mcaselli

Description

@mcaselli

With data ranging to 1.25E6, we get labels of 400K 800K and 1M, which is no good: 1M is labelling 1.2E6.
Should be something like 400K 800K 1.2M, or 0.4M 0.8M 1.2M

library(ggplot2)
library(scales)
library(patchwork)

p <- data.frame(
  category = c("a", "b"),
  value = c(1.25E6, 0.82E6)
) |>
  ggplot(aes(x = category, y = value)) +
  geom_col()

p_1 <- p + labs(title = "default", subtitle = "OK")

p_2 <- p + 
  scale_y_continuous(labels = label_comma()) + 
  labs(title = "label_comma()", subtitle = "OK")

p_3 <- p + 
  scale_y_continuous(labels = label_comma(scale_cut = cut_short_scale())) +
  labs(title = "label_comma(scale_cut = cut_short_scale()", subtitle = "NOT OK")

p_1 + p_2 + p_3

Created on 2025-11-10 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions