Hi,
My issue is that I want to use subscripts and space at the same time on an axis. However, if I use the following scales::parse_format() code then I got an error at the space. I also enclose a minimal example (see a and b to represent where the error occurs).
Thank you for your help in advance,
M
library(tidyverse)
mpg_a <- mpg %>%
mutate(term = paste0(model, " [", year, "]"))
mpg_a %>%
select(term, cty) %>%
head(2)
#> # A tibble: 2 x 2
#> term cty
#> <chr> <int>
#> 1 a4 [1999] 18
#> 2 a4 [1999] 21
ggplot(head(mpg_a, 5), aes(term, cty)) +
geom_col() +
scale_x_discrete(labels=scales::parse_format())
mpg_b <- mpg %>%
mutate(term = paste0(model, " ", class, " [", year, "]"))
mpg_b %>%
select(term, cty) %>%
head(2)
#> # A tibble: 2 x 2
#> term cty
#> <chr> <int>
#> 1 a4 compact [1999] 18
#> 2 a4 compact [1999] 21
ggplot(head(mpg_b, 5), aes(term, cty)) +
geom_col() +
scale_x_discrete(labels=scales::parse_format())
#> Error in parse(text = text[[i]]): <text>:1:4: unexpected symbol
#> 1: a4 compact
#> ^
Created on 2021-02-20 by the reprex package (v0.3.0)