Another example of plotmath

plotmath is very powerful but also not very simple to use.
See ?plotmath

Here is another example of formatting:

> plot(1:100,main="ABCD",cex.main=1.3)
> a=100; b=10
> mtext(bquote(bold(.(formatC(1.2*a,decimal.mark=",",digits=2,format="f")))~" series "~bold(.(formatC(b, digits=0,format="f")))~" items"))
> text(x=1, y=50, bquote(bold(.(formatC(1.2*a,decimal.mark=",",digits=2,format="f")))~" series "~bold(.(formatC(b, digits=0,format="f")))~" items"), pos=4)

The result is:
Some explanations:
~ is a linker between two objects with a space: text(x=1, y=50, bquote("a"~"b"), pos=4)
* is a linker between two objects without a space: text(x=1, y=50, bquote("a"*"b"), pos=4)
use \" between " to show the " character: text(x=1, y=50, bquote("\"a\""*"\"b\""), pos=4)
The "" are not necessary; objects are treated as characters by default: text(x=1, y=50, bquote(a~b), pos=4)
.(x) will return the value of x: text(x=1, y=50, bquote(.(a)~b), pos=4)
bold(x) will print x in bold: text(x=1, y=50, bquote(bold("a")~b), pos=4)
bold(.(x)) does not work if x is numeric: text(x=1, y=50, bquote(bold(.(a))~b), pos=4)
bold(.(as.character(x))) works instead: text(x=1, y=50, bquote(bold(.(as.character(a)))~b), pos=4)


Commentaires

Posts les plus consultés de ce blog

Standard error from Hessian Matrix... what can be done when problem occurs

stepAIC from package MASS with AICc

Install treemix in ubuntu 20.04