writing a label in R for a plot using text, and subscripts using either bquote, paste or expression

荒凉一梦 提交于 2020-06-18 10:45:13

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!