Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use two variables in title of a plot in R?

How do I use variables in Latex expressions in R?

For example:

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 "," in Output? How do I do that?

like image 678
user2227801 Avatar asked Jan 13 '23 19:01

user2227801


2 Answers

Instead of expression you can use bquote() to get desired effect. .(a) ensures that it is replaced by actual a value, *"," adds comma to the expression.

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

enter image description here

like image 188
Didzis Elferts Avatar answered Jan 16 '23 09:01

Didzis Elferts


You can use substitute instead of 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)))

enter image description here

like image 23
Sven Hohenstein Avatar answered Jan 16 '23 09:01

Sven Hohenstein