Update: Appears that there was a desire to pass a variable from outside an expression into an expression-classed variable constructed outside the plot
call. This seems much less complex than using an eval(parse(text=paste( ... ))
construction:
unit=quote(beta)
ylab<-bquote(.(unit)/ml)
plot(1:10, ylab=ylab)
The lesson being illustrated here is using quote
to prevent evaluation of a symbol and then to evaluate to a name inside an expression.
Could also have used either as.name
or as.symbol
:
unit=as.name('beta')
Answer to the question I originally suspected is being asked, since it's one (actually two) I struggled with in my early years of R. I'm guessed that you want to construct tick labels rather than axis labels and that you want these to appear as greek letters or other plotmath
-y constructions, but with ascending "indexing" values substituted. The second request requires using either substitute
or bquote
, while the first request require remembering to suppress the y-axis ticks and lables with a par
argument and then using axis
.
plot(1:10, ylab=ylab,yaxt="n")
# Now create "horizontally aligned" (using las=2) beta-value tick labels
axis(2, at=1:10,
labels=as.expression(lapply( 1:10, function(x) bquote( beta == .(x)))) ,
las=2)
The as.expression
wrapper around a list of bquote
-ed-results is something I found in an earlier answer (by me) and I thought of just labeling as a duplicate, but it didn't involve any plotting so I decided to consider it a "partial overlap".