gpt4 book ai didi

r - 在动态变化的图中显示分数

转载 作者:行者123 更新时间:2023-12-01 13:37:45 27 4
gpt4 key购买 nike

我想知道如何实际显示一个条件计算(见下文) 我正在使用它来获得我在 R 代码中调用的 GG(见代码下面)?

详细信息:

准确地说,我想在我的情节中显示 GG = G1/G2(显示 IF type = 1)和 ELSE GG = (G1/G2 ) * 2(显示 IF type == 2)。

例如,如果 G1 = 1,G2 = 2,我希望根据“类型”显示的内容是以下之一:

enter image description here

注意:在上图中,我匆忙使用了“X 2”,但我需要一个实际的类似 x 的数学符号作为乘号

下面是我的 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 )

最佳答案

使用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)

enter image description here

注意:乘号(×)的ASCII码是Alt 0215

关于r - 在动态变化的图中显示分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42566213/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com