user138773 user138773 - 9 months ago 38
R Question

replacing the multiplication sign (i.e., "x") with its ASCII code in text() in R

I'm wondering how I can replace the multiplication sign (i.e., x) with its ASCII code (

Alt 0215
) in my current
text()
code in R below?

NOTE: If you know of any code other than ASCII for the multiplication sign (i.e., x) that is compatible with
Shiny
that would be OK.

Here is my R code:

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)

Answer Source

Try this:

plot(1:10, ty = "n", ann = F, bty = "n")
v <- if (type == 1) G1/G2 * 2 else G1/G2
text(6, 6, bquote({GG == frac(.(G1), .(G2)) * " \u00D7 2"} == .(v)),
 col = "red4", cex = 1.6)