本文介绍了在plotmath表达式中包含文本控制字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法获取文本字符串的控制字符,例如\\\
for newline 在plotmath表达式内进行评估,反之亦然。在以下示例中,我想结合:




  • 某些字符文本

  • 文本控制字符(换行)

  • 替换变量名称

  • 包含plotmath表达式



阅读后,我可以使用替代方式获得大部分方式,但 newline 不评估字符。我现在正在循环,并将自己与 plotmath parse bquote 替换。在进行绘图,它说

这是不是真的是不可能的?

  lab =some数据
form =指数
x = 1:10
y = x ^ 2


plot(x,y,type =b )
title(main = substitute(paste(Plot of,phi,of:,lab,\\\
Functional form:,form),list(lab = lab,form = form) adj = 0)
解决方案

正如你所想的 plotmath 不支持换行,但您可以使用 mtext bquote ,以写每行。例如,我创建一个行列表:

 行<  -  list(bquote(paste(Plot of,phi, (。),(实验室)))
bquote(粘贴(功能形式:,。(形式)))

mtext(do.call ,side = 3,line = 1:0)

Is there any way to get control characters for text strings, e.g. "\n" for newline evaluated inside a plotmath expression, or vice versa. In the following example, I would like to combine:

  • some character text
  • text control character (newline)
  • substitute a variable name
  • include a plotmath expression

After reading this question I can get most of the way there with substitute, but the newline character is not evaluated. I am now going round in circles and confusing myself with plotmath, parse, bquote and substitute. In the help page for plotmath it says

Does this mean it really is impossible?

lab = "some data"
form = "Exponential"
x = 1:10
y = x^2


plot( x , y , type = "b" )
title( main = substitute( paste( "Plot of " , phi , " of: "  , lab , "\nFunctional form: " , form ) , list(lab = lab , form = form ) ) , adj = 0 )
解决方案

As you have figured plotmath does not support newlines within, but you can use mtext with bquote, to write each line. For example I create a list of lines :

Lines <- list(bquote(paste( "Plot of " , phi , " of: "  , .(lab))),
              bquote(paste("Functional form: " , .(form)))

mtext(do.call(expression, Lines),side=3,line=1:0)

这篇关于在plotmath表达式中包含文本控制字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 16:27