如何在R中下标+, - ,_和其他算术符号

时间:2017-07-05 05:09:41

标签: r ggplot2 syntax-error

以前关于R中下标的问题(特别是与ggplot / annotate / geo参数中的文本有关)并未涉及此问题。

说我想要下标" +",如

$ \西格玛_ + $

如果我做的话

scale_colour_manual(values = c('red' = 'red','blue' = 'blue'),name = '', 
                  labels = expression(P[+] - P[-] == P[w])

我们收到类似于以下错误:

Error: unexpected ']' in:
"scale_colour_manual(values = c('red' = 'red','blue' = 'blue'),name = '', 
labels = expression(P[+]"

1 个答案:

答案 0 :(得分:1)

我认为R认为+是作为一个arithematic运算符,并添加两个非数字“[”和“]”。

解决方案是将下标设为字符串。我认为有些人可能会忘记这是一种可能性。

scale_colour_manual(values = c('red' = 'red','blue' = 'blue'),name = '', 
                  labels = expression(P["+"] - P["-"] == P[w])