2

I am interested in creating a label for ggplot that includes non-standard characters and glyphs. In particular, I am interested in printing BETA^WAZ, BETA^DDC, i.e. where the BETA is the Greek glyph and WAZ and DDC are superscript capitals. Based on the guide here and other resources I have come up with the following:

paste0("Corr(\u03B2", "\u1D42", "\u1D2C", "\u2C6B", ", ", "\u03B2", "\u1D30", "\u1D30", "\uA7FD", ")"))

However, this is not the correct C character. In addition, there does not appear to exist a unicode superscript capital Z. Does anyone know of a resource that would have such a character?

EDIT: I may be mistaken but bquote() does not appear to provide what I'm looking for either; for example, see dummy code below, which does not produce the desired label:

data <- data.frame(x = c(0, 1, 2, 3, 4),
y = c(0, 1, 2, 3, 4))

plot <- ggplot(data, aes(x = x, y = y)) +
  geom_line() +
  xlab(paste0("Corr(", bquote(beta^WAZ), ", ", bquote(beta^DDC), ")"))
Wilson King
  • 25
  • 1
  • 6
  • Are you sure you need to do this in Unicode characters? I don't know ggplot well, but you can do this with standard R plotting - `plot(0:1); text(1.5, 0.5, bquote(Beta^WAZ))` – thelatemail Oct 06 '22 at 22:58
  • The `bquote()` approach should work with ggplot2 too, e.g. https://stackoverflow.com/q/37825558/12957340 - if you could please expand your example @Wilson King it might help with troubleshooting – jared_mamrot Oct 06 '22 at 23:01
  • 1
    @jared_mamrot I've edited now with an example. `bquote()` does not appear to work and produces a label Corr(^, ^) – Wilson King Oct 06 '22 at 23:11
  • I don't think you're doing the expression correctly. E.g. `xlab('Corr('~beta^WAZ~','~beta^DDC~')')` works okay. – thelatemail Oct 06 '22 at 23:35

1 Answers1

1

The answer in the @thelatemail's comment above didn't render correctly on my system, so here is another potential solution using bquote():

library(ggplot2)
data <- data.frame(x = c(0, 1, 2, 3, 4),
                   y = c(0, 1, 2, 3, 4))

ggplot(data, aes(x = x, y = y)) +
  geom_line() +
  xlab(bquote("Corr(\u03B2" ^WAZ~", \u03B2" ^DDC~")"))

Created on 2022-10-07 by the reprex package (v2.0.1)

jared_mamrot
  • 22,354
  • 4
  • 21
  • 46