在R中为使用文本的图形编写标签,并使用bquote,paste或expression编写下标 [英] writing a label in R for a plot using text, and subscripts using either bquote, paste or expression
问题描述
我在使用引号,粘贴和表达方式时遇到一些困难.
我使用了一个程序包,该程序包根据从数据文件获得的一些结果为我提供了一些绘图.结果保存为对象(MIN.ED
和MIN.error
).
对于图,我想使用那些结果对象和文本来标记图上的某些线.
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.
对于标签,我使用以下
line1abel<-paste("MAM"[3],MIN.ED,"\U00B1",MIN.error)
我尝试使用
"MAM"["3"}
或
"MAM[3]"
,并继续获得NA.
I have tried variants using
"MAM"["3"}
or
"MAM[3]"
and keep on getting NA.
MAM是模型类型,3是用于该模型的参数数量. 我希望将其显示为MAM下标3,但我得到的只是NA,后跟MIN.ED的值±MIN.error的值.
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.
我看完了不同的下标后,我真的看不到为什么我得到了NA值.我看到有些帖子使用bquote
,而其他帖子expressions
等,但是对于绘图包,我需要将线标签指定为line.labels=c(line1lable,line2label...)
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...)
如何用文本MAM和下标"3"构建标签表达式,为什么我得到"NA"?我以为粘贴允许将文本和结果有效地链接为文本,并且在最坏的情况下,我将拥有MAM [3] 44±2而不是NA 44±2!
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!
推荐答案
MAM <- "text"
grid::grid.text(bquote(.(MAM)[3]))
这篇关于在R中为使用文本的图形编写标签,并使用bquote,paste或expression编写下标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!