Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expression + variable value + normal text in plot maintitle [duplicate]

Tags:

i want to achieve an title in R plot as the following:

title = "The significance level you entered is alpha = 0.05 which is often used."

In order to get this I split the whole text in little parts, so i finally can write

title = paste(part1,part2,part3,part4)

The parts are:

part1 = "The significance level you entered is"

part2 = expression(alpha)

part3 = object@attribute

part4 = " which is often used."

So I'm not able to combine these parts to get my result.

Either the symbol is shown correctly and the part 3 is printed as object@attribute (ant not his value) or the symbol is not shown and the value of the object is printed correctly.

I used ?expressionand ?printalready, but didn't get it

The examples provided in ?plotmath didn't match my case either.

like image 738
user3093283 Avatar asked Dec 11 '13 23:12

user3093283


1 Answers

One solution is to use bquote(). Use .() within bquote to get the value of objects or expressions. Here is one example of how that might work:

obj = list(foo=0, bar=99, alpha=0.05)
plot(1:10, main=bquote("Significance level is" ~ alpha == .(obj$alpha)))

The tilde ~ seems necessary here to convince bquote to treat alpha as a plotmath expression.

enter image description here

like image 120
bdemarest Avatar answered Nov 12 '22 01:11

bdemarest