3

我正在尝试在我的情节中格式化图例,但由于希腊语和上标,我必须使用 expression() 。但是,当我想显示 r^2 = 0.45, P<0.0001,当我输入时,我得到 r^2 = 0.45 P<1e-04

legend(expression(r^2==0.9230~~P<0.0001))

我尝试查找 list() 函数,但它对逗号没有帮助。我也找不到在 expression() 函数中使用小数的任何内容。

任何建议,将不胜感激。

谢谢

4

2 回答 2

12

You can use paste() (within the call to expression()) to splice together character strings and unquoted expressions. The unquoted bits will be evaluated using the special rules exhibited by example(plotmath) and demo(plotmath), while the character strings will be printed verbatim.

Here's an example (which also uses phantom(), because the < operator expects/needs something to both its left and its right):

plot(1)
legend(x = "topleft", 
       legend = expression(paste(r^2==0.9230, ",  ", P<phantom(), "0.0001")))

enter image description here

于 2012-11-02T19:21:50.980 回答
5

这是另一种使用方法substitute,可以避免phantom

plot(1)
options(scipen=10)
legend(x = "topleft", 
       legend = substitute(list(r^2 == r2, P < p), list(r2=0.923, p=0.0001)))

在此处输入图像描述

于 2012-11-02T19:38:01.093 回答