Plot main title in two lines

走远了吗. 提交于 2019-11-27 13:47:54

The root issue is that plotmath does not support newlines within the expressions to be output.

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

You really need to create and output each line separately.

For example :

Lines <- list(bquote(paste("C=", .(CVal))),
              bquote(paste(sum(xi), "=", .(SumEpsVal))))

Now output each line The text in the list is converted to expressions do.call

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

Personally I would use mtext as already suggested. But if you really want it to be a one-liner, you can "cheat" bquote by using atop:

plot(1:10, main=
  bquote(atop(paste("C=",.(CVal)), paste(sum(xi),"=",.(SumEpsVal)))))

It even aligns both lines neatly to the center.

One way to achieve this is to use mtext to add an additional line under the main title as follows:

plot(1:10, main=bquote(paste("C=", .(CVal))))
mtext(bquote(paste(sum(xi), "=", .(SumEpsVal) )),side=3,line=0)

There may be a prettier solution, but perhaps this is enough for your needs.

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