How to use two variables in the chart title in R?

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?

+4
source share
2 answers

You can use substitute instead of expression . The second argument is a list that defines replacement strings and objects.

 a <- 5 b <- 1 plot(1, 1, main = substitute(paste(p == a, ", ", q == b), list(a = a, b = b))) 

enter image description here

+4
source

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.

 a<-5 b<-1 plot(1:10, main=bquote(p==.(a) *"," ~q==.(b))) 

enter image description here

+5
source

All Articles