是否可以在 R 数学符号中使用 == 两次?

Is it possible to use == twice in R mathematical notation?

我正在尝试在绘图标签中使用 plotmath 的 R 数学符号。在标签中,我试图使用等号,例如

ggplot(data=NULL) +
  geom_point(aes(x=0.5, y=0)) +
  geom_text(aes(x=0.5, y=-0.1),
            label = paste("x == frac(3,2) == 1.5"), parse=TRUE) +
  xlim(-1,1) +
  ylim(-1, 1)

但是,我收到以下错误:

Error in parse(text = text[[i]]) : <text>:1:16: Unexpected '=='
1: x == frac(3,2) ==
                   ^

是否可以在一个标签中使用两个等号?

(这是 的后续问题。)

ggplot(NULL) +
  geom_point(aes(x = 0.5, y = 0)) +
  annotate("text", x = 0.5, y = -0.2, label = expression(paste("x = ", frac(3, 2), " = 1.5"))) +
  annotate("text", x = 0.5, y = 0.2,  label = "~x == ~frac(3, 2) == ~1.5", parse = T) +
  annotate("text", x = 0.5, y = -0.4, label = expression({x == frac(3, 2)} == 1.5)) +
  xlim(-1, 1) +
  ylim(-1, 1)

您可以使用 paste 连接这两个语句,但您可能需要通过在第二个表达式的左侧放置一个空白变量名来作弊。

ggplot(data=NULL) +
  geom_point(aes(x=0.5, y=0)) +
  geom_text(aes(x=0.5, y=-0.1),
            label = paste("paste(x == frac(3,2), ` ` == 1.5)"), parse=TRUE) +
  xlim(-1,1) +
  ylim(-1, 1)