如何将文本下标添加到ggplot2因子标签中的特殊字符?

How to add a text subscript to a special character in ggplot2 factor label?

我需要首​​先重新标记因子,以便有字母符号后跟文本下标。我遵循了几个地方的几个例子并尝试了以下方法。

df <- data.frame(alpha = c("aii","aij","ajj","aji"), count = c(1,2,3,4))

ggplot(aes(x = alpha, y = count), data = df) + geom_points()+
    scale_x_discrete(labels=c("aii" = bquote(\u03b1 [ii]), "aij" = bquote(\u03b1 [ij]),
                              "ajj" = bquote(\u03b1 [jj]),"aji" = bquote(\u03b1 [ji]))

其中 \u03b1 是 alpha 的 unicode

我得到Error: unexpected input in: "aii" = bquote(\u03b1 [ii])

关于如何进行的任何建议。

bquote() 需要用引号括起 unicode,而对 geom_point() 的调用拼写错误。

library(ggplot2)

df <- data.frame(alpha = c("aii","aij","ajj","aji"), count = c(1,2,3,4))

ggplot(aes(x = alpha, y = count), data = df) + 
  geom_point() +
  scale_x_discrete(labels=c("aii" = bquote("\u03b1" [ii]), "aij" = bquote("\u03b1" [ij]), 
                            "ajj" = bquote("\u03b1" [jj]),"aji" = bquote("\u03b1" [ji])))