How to use variables in Latex expressions in R?
For instance:
a<-5; b<-1; plot(X, Y, main=expression(paste(p==a,q==b)))
a and b are R variables. Also I want to have a "," in Output? How to do it?
a
b
You can use substitute instead of expression . The second argument is a list that defines replacement strings and objects.
substitute
expression
a <- 5 b <- 1 plot(1, 1, main = substitute(paste(p == a, ", ", q == b), list(a = a, b = b)))
Instead of expressing, you can use bquote() to get the desired effect. .(a) ensures that it is replaced with the actual value of a , *"," adds a comma to the expression.
bquote()
.(a)
*","
a<-5 b<-1 plot(1:10, main=bquote(p==.(a) *"," ~q==.(b)))