Owing to the journal's formatting requirement, I need to use a true negative sign (UTF-16: 2212) for my graphs. This is similar to 
May I ask if there is a more elegant and/or dynamic solution to this?
CodePudding user response:
You can write your own labeller function.
library(ggplot2)
label_trueminus <- function(x){
ifelse(sign(x) == -1, paste0("\u2212", abs(x)), x)
}
ggplot(mtcars, aes(mpg-20, disp))
geom_point()
scale_x_continuous(labels = label_trueminus)

Created on 2022-01-25 by the reprex package (v2.0.1)
CodePudding user response:
or even shorter:
library(tidyverse)
label_parse <- function(breaks) {
parse(text = breaks)
}
# sample data
tibble(
a = -5:5,
b = rnorm(length(a))
) %>%
# sample plotting
ggplot(aes(a,b))
geom_point()
# here's the magic
scale_x_continuous(labels = label_parse)
