[英]How do I use two variables in title of a plot in R?
How do I use variables in Latex expressions in R? 如何在R中的Latex表达式中使用变量?
For example: 例如:
a<-5; b<-1; plot(X, Y, main=expression(paste(p==a,q==b)))
a
and b
are R variables. a
和b
是R变量。 Also I want to have "," in Output? 另外我想在输出中有“,”? How do I do that? 我怎么做?
Instead of expression you can use bquote()
to get desired effect. 您可以使用bquote()
来获得所需的效果,而不是表达式。 .(a)
ensures that it is replaced by actual a
value, *","
adds comma to the expression. .(a)
确保它是由实际替换a
值, *","
增加逗号到表达式。
a<-5
b<-1
plot(1:10, main=bquote(p==.(a) *"," ~q==.(b)))
You can use substitute
instead of expression
. 您可以使用substitute
而不是expression
。 The second argument is a list specifying replacement strings and objects. 第二个参数是指定替换字符串和对象的列表。
a <- 5
b <- 1
plot(1, 1, main = substitute(paste(p == a, ", ", q == b), list(a = a, b = b)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.