Consider this simple example:
labNames <- c('xLab','yLabl')
plot(c(1:10),xlab=expression(paste(labName[1], x^2)),ylab=expression(paste(labName[2], y^2)))
What I want is for the character entry defined by the variable ‘labName,
‘xLab’ or ‘yLab’ to appear next to the X^2 or y^2 defined by the expression(). As it is, the actual text ‘labName’ with a subscript is joined to the superscripted expression.
Any thoughts?
An alternative solution to that of @Aaron is the
bquote()function. We need to supply a valid R expression, in this caseLABEL ~ x^2for example, whereLABELis the string you want to assign from the vectorlabNames.bquoteevaluates R code within the expression wrapped in.( )and subsitutes the result into the expression.Here is an example:
(Note the
~just adds a bit of spacing, if you don’t want the space, replace it with*and the two parts of the expression will be juxtaposed.)