[英]Superscript R squared for legend
I want to write a R-squared term for my legend but I do not know how. 我想为我的传说写一个R平方的术语,但我不知道如何。 Could someone help me please?
有人可以帮帮我吗? My legend syntax is:
我的传奇语法是:
legend(2,10, c("BW (MPE=3%, R-squared=0.77)",
"MY (MPE=5%, R-squared=0.80)", pch=c(2,3))
I would liek to express R-squared as R2 as we normally have in the text. 我会像文本中通常所说的那样将R平方表示为R2。
It will work if you combine bquote
and as.expression
: 如果你把
bquote
和as.expression
结合起来bquote
as.expression
:
plot(1:10)
legend(2, 10, c(as.expression(bquote("BW (MPE = 3%," ~ R^2 ~ "= 0.77)")),
as.expression(bquote("MY (MPE = 5%," ~ R^2 ~ "= 0.80)"))),
pch=c(2,3))
This is less complex than using c( as.expression ( bquote...
multiple times: 这比使用
c( as.expression ( bquote...
多次:
plot(1:10)
legend(2, 10, expression("BW (MPE = 3%," ~ R^2 ~ "= 0.77)",
"MY (MPE = 5%," ~ R^2 ~ "= 0.80)"),
pch=c(2,3))
It is useful to understand that the expression
function is really a way to make lists of expressions and that commas are then reserved as separators for that process. 理解
expression
函数实际上是一种制作表达式列表的方法很有用,然后将逗号保留为该进程的分隔符。 This means you cannot have a "naked" comma in something you want to be inside one of the distinct elements. 这意味着你不能在一个你想要在一个不同元素中的“裸”逗号。 The commas immediately after the
%
-signs are protected from parsing by the quotes. %
-signs之后的逗号会受到保护,不会被引号解析。 This could fully plotmath()-ified with: 这可以完全plotmath() - ified with:
plot(1:10)
legend(2, 10, expression(BW * list(MPE == 3*'%',
R^2 == 0.77),
MY * list( MPE == 5*'%',
R^2 == 0.80)
),
pch=c(2,3))
That way the only character needing special attention is the '%'-sign which plotmath() uses to delimit its specials. 这样,唯一需要特别注意的角色是'%' - plotmath()用来分隔其特殊内容的符号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.