4

假设 x 和 y 是变量。我正在尝试创建一个与 Latex 等效的图形标题 $\sigma_v =$ 3 $\rho =$ 5,其中值 3 和 5 来自 R 变量。

这是我能做到的最接近的(仿照 ?plotmath 中的一个例子):

x <- 1:10
y <- 3
z <- 5
plot(x,x)
mtext(substitute(list(sigma[v],rho) == group("(",list(a,b),")"),list(a=y,b=z)))

是否有可能有一系列“变量=数字”字符串?

4

2 回答 2

3

You can use bquote() to do what you said you wanted (LaTeX equivalent). Here is an example:

x <- 1:10
y <- 3
z <- 5
plot(x,x)
title(main = bquote(sigma[v] == .(y) ~~ rho == .(z)))
于 2012-02-15T15:53:07.827 回答
2

The LaTex expression didn't have a comma separating the two pairs but it appears you did want one in there so see if this is a good solution:

mtext(substitute(sigma[v] == a *","~ rho == b, list(a=y,b=z)))

To comment on the notion of "concatenating expressions" raised by mcd: Valid (invisible) "concatenators" are ~ and * and the (visible) infix operators. Spaces are not valid separators (and they are ignored). You do not need to quote anything except commas, parentheses not used for visible grouping of uninterpreted sub-expressions, and carets and brackets not used for their side-effects. Sometimes it is handier to quote a long line of text because spaces are easier to type than multiple *'s or tilde's to separate non-plotmath-ish words.

于 2012-02-15T15:52:20.267 回答