在 plotmath 表达式中包含文本控制字符 [英] Include text control characters in plotmath expressions

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

问题描述

有没有办法获取文本字符串的控制字符,例如" " 用于 newline 在 plotmath 表达式中求值,反之亦然.在下面的例子中,我想结合:

  • 一些字符文本
  • 文本控制字符(换行符)
  • 替换变量名
  • 包含绘图数学表达式

在阅读这个问题后,我可以用替代来解决大部分问题,但是换行符代码> 字符不被评估.我现在绕圈子,把自己弄糊涂了 plotmathparsebquotesubstitute.在 plotmath 的 帮助页面 中,它说 ><块引用>

与普通绘图不同,控制字符(例如 )不会在 plotmath 中的字符串中解释.

这是否意味着它真的不可能?

lab = "一些数据"形式 = "指数"x = 1:10y = x^2绘图( x , y , type = "b" )标题(主要 = 替代(粘贴(Plot of",phi,of:",lab,
函数形式:",form),list(lab=lab,form=form)),adj=0)

解决方案

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

Lines <- list(bquote(paste( "Plot of " , phi , " of: " , .(lab))),bquote(paste("函数形式:" , .(form)))mtext(do.call(expression, Lines),side=3,line=1:0)

Is there any way to get control characters for text strings, e.g. " " 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

Control characters (e.g. ) are not interpreted in character strings in plotmath, unlike normal plotting.

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 , "
Functional 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 表达式中包含文本控制字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆