Latex and variables in plot label in R?

前端 未结 4 1181
盖世英雄少女心
盖世英雄少女心 2021-02-15 04:20

How do I use variables in Latex expressions in R?

For example:

plot(X, Y, main=expression(R^2))

Will put R with a nice superscripted 2

4条回答
  •  青春惊慌失措
    2021-02-15 05:09

    Another variation on @Joris' theme is substitute(). You give substitute() an expression and an environment or list within which to evaluate the expression. Passing a list is usually easiest, especially for jobs such as the one posed here.

    plot(X,Y, main = substitute(R^2 : a, list(a = a)))
    

    We can see why this works, by looking solely at the substitute() call:

    > substitute(R^2 : a, list(a = a))
    R^2:0.8
    

    The a in the expression is replace with the value of a in the list.

提交回复
热议问题