Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
495 views
in Technique[技术] by (71.8m points)

r - Include text control characters in plotmath expressions

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 )

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...