Add macron to letter in faceting label

Viewed 52

As the title says, I want to add a macron to a faceting label. An example:

library(tidyverse)

# subset data
df2 <- diamonds %>%
  sample_n(500)

# plot
ggplot(df2,aes(x = carat, y = price)) +
  geom_point() +
  facet_wrap(~cut)

enter image description here

Now I want to add a macron over the a in Fair

# attempt to recode Fair to Fāir
df2 <- df2 %>%
  mutate(cut2 = fct_recode(cut, "F\u0101ir" = "Fair"))

# doesn't work - produces exactly the same plot as above.
ggplot(df2,aes(x = carat, y = price)) +
  geom_point() +
  facet_wrap(~cut2)

Any tips would be greatly appreciated.

1 Answers

Looks like it's a problem with fct_recode rather than ggplot2. This seems to work just fine

df2 <- diamonds %>%
  sample_n(500)
df2$cut2 <- df2$cut
levels(df2$cut2)[1] <- "F\u0101ir"

ggplot(df2,aes(x = carat, y = price)) +
  geom_point() +
  facet_wrap(~cut2)

plot with facet with macron

Actually I guess it has to do with all parameter names in R. It doesn't look like you can use unicode names (at least not in 4.0.5 which I tested with)

foo <- function(...) {
  print(match.call())
}
foo("F\u0101ir" = 1)
# foo(Fair = 1)
foo(Fāir = 1)
# foo(Fair = 1)

Seems the values are just converted to ASCII

Related