R中情节标签中的乳胶和变量? [英] Latex and variables in plot label in R?

查看:62
本文介绍了R中情节标签中的乳胶和变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在R的Latex表达式中使用变量?

How do I use variables in Latex expressions in R?

例如:

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

将R带一个漂亮的上标2作为主标题.

Will put R with a nice superscripted 2 as main title.

但是,假设我想说"R ^ 2:0.5",其中0.5来自R变量.我该怎么办?

But let's say I want it to say 'R^2: 0.5', with 0.5 coming from a R variable. How do I do that?

推荐答案

Owen的破解很酷,但实际上并不是实现该目的的常用方法.如果使用bquote,这实际上很容易. bquotequote的作用相同,不同之处在于.()之间的所有内容都将在指定的环境(或全局环境,如果未指定任何内容)中进行评估.

The hack of Owen is pretty cool, but not really the common way to do that. If you use bquote, this is actually pretty easy. bquote will do the same as quote, with the exception that everything between .() will be evaluated in a specified environment (or the global, if nothing is specified).

一个简单的例子:

X <- 1:10
Y <- 1:10
a <- 0.8
plot(X,Y,main=bquote(R^2 : .(a)))

礼物:

有关更多示例和可能性,另请参见?bquote?plotmath

See also ?bquote and ?plotmath for more examples and possibilities

这篇关于R中情节标签中的乳胶和变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆