tags:

views:

71

answers:

1

In R, I'm wanting to create a graph with x axis label expression(varname), where varname is a character object. For example:

varname <- "beta[1]"
hist(rnorm(20),xlab=expression(varname))

But that gives me a graph with xlab="varname" rather than xlab=expression(beta[1]). How to I convince expression() to evaluate the variable?

+5  A: 

you can do by

hist(rnorm(20),xlab=parse(text=varname))
kohske
Thanks. I knew it would be simple, but the help files didn't seem to have anything like it.
Rob Hyndman
Mathematical notation can be defined as an expression in any of the text-drawing functions (text, mtext or axis). Output is formatted in a similar way to TeX, so for TeX users, this transition is easy. For a complete overview of symbols see the help file on `plotmath` and run the demonstration
Brani