问题
I am having some difficulty with the use of quote, paste and expression.
I use a package that gives me some plot based on some results obtained from a data file. The results are saved as objects (MIN.ED
and MIN.error
).
For the plot, I would like to label some of the lines on the plot using those result objects as well as text.
For the label I use the following
line1abel<-paste("MAM"[3],MIN.ED,"\U00B1",MIN.error)
I have tried variants using
"MAM"["3"}
or
"MAM[3]"
and keep on getting NA.
MAM is the model type and 3 is the number of parameters used for that model. I would like that to appear as MAM subscript3 but all I get is NA followed by the value for MIN.ED ± value for MIN.error.
I have looked right through the different subscript posts and I really cannot see why I get that NA value. I see that some posts use bquote
, and others expressions
etc, but with the plotting package, I need to to give the line labels as line.labels=c(line1lable,line2label...)
How can build the label expression with the text MAM and subscript "3" and why is it that I get a "NA"? I thought paste allowed to link effectively text and results as text and that at worst I would have had MAM[3] 44 ± 2 rather than NA 44 ± 2!
回答1:
MAM <- "text"
grid::grid.text(bquote(.(MAM)[3]))
来源:https://stackoverflow.com/questions/40326969/writing-a-label-in-r-for-a-plot-using-text-and-subscripts-using-either-bquote