我想知道如何在当前的 text() 中用 ASCII 代码 (
下面的 R 代码?Alt 0215
) 替换乘号(即 x)
注意:如果您知道乘号(即 x)除 ASCII 之外与 Shiny
兼容的任何代码,那就没问题了。
这是我的 R 代码:
G1 = 1
G2 = 2
type = 1
plot(1:10, ty = "n", ann = F, bty = "n")
text(6, 6,
bquote(paste("GG = ", frac(.(G1), .(G2)),
.(ifelse(type == 1, " × 2", "")), ## HERE is where I need to use the ASCII code for "×"
" = ",
.(ifelse(type == 1, G1/G2 * 2, G1/G2)), sep = "")),
col = "red4", cex = 1.6)
最佳答案
试试这个:
plot(1:10, ty = "n", ann = F, bty = "n")
b <- if (type == 1) {
bquote({GG == frac(.(G1), .(G2)) * " \u00D7 2"} == .(2 * G1/G2))
} else bquote({GG == frac(.(G1), .(G2))} == .(G1/G2))
text(6, 6, b, col = "red4", cex = 1.6)
对于type <- 1
这是结果:
关于将乘号(即 "x")替换为 R 中 text() 中的 ASCII 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42738638/