plotmath {base} | R Documentation |
If the text
argument to one of the text-drawing functions
(text
, mtext
, axis
) in R
is an expression, the argument is interpreted as a mathematical
expression and the output will be formatted according to TeX-like
rules.
A mathematical expression must obey the normal rules of syntax for any R expression, but it is interpreted according to very different rules than for normal R expressions.
For example, a+b
, a-b
, and a/b
, produce
a+b, a-b, and a/b, but a*b
produces
ab.
For example, +x
produces +x and -y
produces
-y.
For example, x[i]
produces x_i and x^2
produces x^2.
hat
and bar
.
frac
(or its alias, over
).
==
relation.
For example, x == y
produces x=y.
For example, (x+y)
produces (x+y).
For example, x^{2*y}
produces x^{2y}, whereas
x^2*y
produces x^2y.
For example, sum(x[i], i==0, n)
produces
sum_{i=0}^n x_i
root
and sqrt
.
abs
.
For example, abs(x)
produces |x|.
paste
.
For example, paste(over(b, 2), y, sum(x))
produces
b/2 y sum(x).
bold
, italic
,
plain
, and bolditalic
. Note that these font
specifications do not accumulate (i.e., bold(italic(x)))
gives an italic `x', whereas bolditalic(x)
produces a bold,
italic `x').
For example, foo(x)
produces foo(x).
x <- seq(-4, 4, len = 101) y <- cbind(sin(x), cos(x)) matplot(x, y, type = "l", xaxt = "n", main = expression(paste(plain(sin) * phi, " and ", plain(cos) * phi)), ylab = expression("sin" * phi, "cos" * phi), # only 1st is taken xlab = expression(paste("Phase Angle ", phi)), col.main = "blue") axis(1, at = c(-pi, -pi/2, 0, pi/2, pi), lab = expression(-pi, -pi/2, 0, pi/2, pi)) plot(1:10, 1:10) text(4, 9, expression(hat(beta) == (X^t * X)^{-1} * X^t * y)) text(4, 8.4, "expression(hat(beta) == (X^t * X)^{-1} * X^t * y)", cex = .8) text(4, 7, expression(bar(x) == sum(frac(x[i], n), i==1, n))) text(4, 6.4, "expression(bar(x) == sum(frac(x[i], n), i==1, n))", cex = .8) text(8, 5, expression(paste(frac(1, sigma*sqrt(2*pi)), " ", plain(e)^{frac(-(x-mu)^2, 2*sigma^2)})), cex= 1.2)