Napier
Napier

Reputation: 227

ggplot labels unit format

Hey i want to change the unit format

and this my code for y scales

scale_y_continuous(labels = scales::unit_format(unit="Rp"))

and the output will be 400 000 Rp

but, i want the output to be like this, Rp 400 000

scale_x_continuous(labels = math_format(x^2)),

it give error message, i want the output like this, enter image description here

Upvotes: 1

Views: 731

Answers (2)

TarJae
TarJae

Reputation: 79184

Here is an example how you can put Rp before the number:

library(tidyverse)
ggplot(mtcars, aes(cyl, mpg)) +
  geom_point() + 
  scale_y_continuous(labels = function(x) paste0("Rp", x))

enter image description here

Upvotes: 1

dy_by
dy_by

Reputation: 1241

for y scales, use prefix

scale_y_continuous(labels = scales::unit_format(prefix ="Rp ", unit = ""))

for x, dont forget a .

scale_x_continuous(labels = scales::math_format(expr = .x^2))

Upvotes: 1

Related Questions