我想知道如何实际显示条件计算(见下文)我用来获取我在R代码中调用GG
的内容(参见下面的代码)?
详细信息:
准确地说,我想在我的情节中显示GG
= G1 / G2(显示为IF type = 1
)和ELSE GG
=(G1 / G2)* 2(显示)如果type == 2
)。
例如,如果G1 = 1,G2 = 2,我希望根据“类型”显示的内容是以下之一:
注意:在上图中,我快速使用了“X 2”,但我需要一个实际的 x-like数学符号作为乘法符号。
以下是我的R代码:
G1 = 1 ## Can be any other number, comes from a function
G2 = 2 ## Can be any other number, comes from a function
type = 1 ## Can be either 1 or 2
plot(1:10,ty="n",ann=F, bty="n")
text( 6, 6, expression(paste("GG = ", ifelse(type==1, frac(G1, G2), frac(G1, G2)*2 ), " = ",
G1/G2, sep = "")), col = "red4", cex = 1.6 )
答案 0 :(得分:3)
使用bquote
,使用.()
将动态值添加到表达式中:
type = 1
plot(1:10, ty = "n", ann = F, bty = "n")
text(6, 6,
bquote(paste("GG = ", frac(.(G1), .(G2)),
.(ifelse(type == 1, " × 2", "")),
" = ",
.(ifelse(type == 1, G1/G2 * 2, G1/G2)), sep = "")),
col = "red4", cex = 1.6)
注意:乘法符号(×)的ASCII代码为Alt 0215
答案 1 :(得分:0)