Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use expression with a variable r

Tags:

r

expression

I am trying to label a plot with the following label:

"Some Assay EC50 (uM)" where the "u" is a micro symbol.

I currently have:

assay <- "Some Assay" plot(0,xlab=expression(paste(assay," AC50 (",mu,"M)",sep=""))) 

But that gives: "assay EC50 (uM)" rather than the desired "Some Assay EC50 (uM)".

Suggestions? Thanks.

I also tried:

paste(assay,expression(paste(" AC50 (",mu,"M)",sep="")),sep="") 
like image 849
dayne Avatar asked Feb 25 '13 18:02

dayne


People also ask

How do you write an expression in R?

Create an Expression in R Programming – expression() Function. expression() function in R Language is used to create an expression from the values passed as argument. It creates an object of the expression class.

What is Bquote R?

bquote() function in R Language is used to quote the arguments passed to it, except the values which are wrapped in '. ()'. It evaluates the wrapped values and quotes the result.

How do you define a variable in R?

A variable in R can be defined using just letters or an underscore with letters, dots along with letters. We can even define variables as a mixture of digits, dot, underscore and letters.


1 Answers

You want a combination of bquote() and a bit of plotmath fu:

assay <- "Some Assay" xlab <- bquote(.(assay) ~ AC50 ~ (mu*M)) plot(0, xlab = xlab) 

The ~ is a spacing operator and * means juxtapose the contents to the left and right of the operator. In bquote(), anything wrapped in .( ) will be looked up and replaced with the value of the named object; so .(assay) will be replaced in the expression with Some Assay.

like image 55
Gavin Simpson Avatar answered Sep 28 '22 07:09

Gavin Simpson