将乘号(即 "x")替换为 R 中 text() 中的 ASCII 代码

标签 r function plot shiny ascii

我想知道如何在当前的 text() 中用 ASCII 代码 (Alt 0215) 替换乘号(即 x) 下面的 R 代码?

注意:如果您知道乘号(即 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这是结果:

screenshot

关于将乘号(即 "x")替换为 R 中 text() 中的 ASCII 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42738638/

相关文章:

删除ggplot图例中的重复标签

r - 使用循环神经网络格式化时间序列数据以进行短期预测

R-tapply 不保持日期格式

c++ - vector<wstring> 作为返回值和参数

Perl Chart::Gnuplot - 访问plot2d 的ASCII 输出

r - 从 Shiny、Plotly - R 中提取所有点击事件图

function - Fortran 是否通过函数和子例程调用保留内部变量的值?

javascript - 创建多次使用的函数

python - 使用 PyPlot 绘制平滑线

r - 如何在 x 轴为时间轴的 R 图中绘制箭头?