Superscript R squared for legend

放肆的年华 提交于 2019-12-03 08:19:02

It will work if you combine bquote and 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:

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. 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. This could fully 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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!