How to change the format/notation of the scale after the y-axis break (ggbreak)?

75 Views Asked by At

I want to format the numbers of the scale after the break as #.# x 10^# to match my other scales. I have done this for the scale before the break with a custom function, which substitutes scientific notation with 10^x notation. Thank you for the help.

scientific_10 = function(x) {
  ifelse(
    x==0, "0",
    parse(text = sub("e[+]?", "%*%10^", scientific_format()(x)))
  )
} 

#example 

test_plot <- ggplot(data, x = groups, y = values) +
  geom_boxplot() +
  scale_y_break(c(210000, 2025000), scales = 0.3, ticklabels = c(2.03e+06, 2.07e+06)) +
          scale_y_continuous(limits = c(0, 2075000), label = scientific_10) +
          theme(axis.text.y.right = element_blank(),
          axis.ticks.y.right = element_blank(),
          axis.line.y.right = element_blank())

example

1

There are 1 best solutions below

1
On

here you go:

ggplot(data, aes(x = groups, y = values)) +
  geom_boxplot() +
  scale_y_break(breaks = c(210000), scales = 0.3) +
  scale_y_continuous(
    breaks = c(0, 50000, 100000, 210000, 2025000),
    limits = c(10000, 2075000),
    labels = scientific_10
  ) +
  theme(axis.text.y.right = element_blank(),
        axis.ticks.y.right = element_blank(),
        axis.line.y.right = element_blank())