## Title: plot-plotmath-001
## Author: Paul Johnson <pauljohn at ku.edu>
## Date posted: 2013-02-05
## Description. Basic exploration of plotmath
## For basics, everybody should run:
## demo(plotmath)
##
## ?plotmath
## Want to use times-roman fonts in the next plot device?
par(family="Times")
## par sets the options used by plots.
## This non-default setting works, but it is only in effect
## for the next graphic device. When you close a graph, then
## type reverts to usual helvetica family.
## Run following plots without it, then with it.
example(plotmath)
##
## pltmth> require(graphics)
##
## pltmth> x <- seq(-4, 4, len = 101)
##
## pltmth> y <- cbind(sin(x), cos(x))
##
## pltmth> matplot(x, y, type = "l", xaxt = "n",
## pltmth+ main = expression(paste(plain(sin) * phi, " and ",
## pltmth+ plain(cos) * phi)),
## pltmth+ ylab = expression("sin" * phi, "cos" * phi), # only 1st is taken
## pltmth+ xlab = expression(paste("Phase Angle ", phi)),
## pltmth+ col.main = "blue")
##
## pltmth> axis(1, at = c(-pi, -pi/2, 0, pi/2, pi),
## pltmth+ labels = expression(-pi, -pi/2, 0, pi/2, pi))
##
## pltmth> ## How to combine "math" and numeric variables :
## pltmth> plot(1:10, type="n", xlab="", ylab="", main = "plot math & numbers")
##
## pltmth> theta <- 1.23 ; mtext(bquote(hat(theta) == .(theta)), line= .25)
##
## pltmth> for(i in 2:9)
## pltmth+ text(i, i+1, substitute(list(xi, eta) == group("(",list(x,y),")"),
## pltmth+ list(x = i, y = i+1)))
##
## pltmth> ## note that both of these use calls rather than expressions.
## pltmth> ##
## pltmth> text(1, 10, "Derivatives:", adj = 0)
##
## pltmth> text(1, 9.6, expression(
## pltmth+ " first: {f * minute}(x) " == {f * minute}(x)), adj = 0)
##
## pltmth> text(1, 9.0, expression(
## pltmth+ " second: {f * second}(x) " == {f * second}(x)), adj = 0)
##
## pltmth> plot(1:10, 1:10)
##
## pltmth> text(4, 9, expression(hat(beta) == (X^t * X)^{-1} * X^t * y))
##
## pltmth> text(4, 8.4, "expression(hat(beta) == (X^t * X)^{-1} * X^t * y)",
## pltmth+ cex = .8)
##
## pltmth> text(4, 7, expression(bar(x) == sum(frac(x[i], n), i==1, n)))
##
## pltmth> text(4, 6.4, "expression(bar(x) == sum(frac(x[i], n), i==1, n))",
## pltmth+ cex = .8)
##
## pltmth> text(8, 5, expression(paste(frac(1, sigma*sqrt(2*pi)), " ",
## pltmth+ plain(e)^{frac(-(x-mu)^2, 2*sigma^2)})),
## pltmth+ cex = 1.2)
##
## pltmth> ## some other useful symbols
## pltmth> plot.new(); plot.window(c(0,4), c(15,1))
##
## pltmth> text(1, 1, "universal", adj = 0); text(2.5, 1, "\\042")
##
## pltmth> text(3, 1, expression(symbol("\042")))
##
## pltmth> text(1, 2, "existential", adj = 0); text(2.5, 2, "\\044")
##
## pltmth> text(3, 2, expression(symbol("\044")))
##
## pltmth> text(1, 3, "suchthat", adj = 0); text(2.5, 3, "\\047")
##
## pltmth> text(3, 3, expression(symbol("\047")))
##
## pltmth> text(1, 4, "therefore", adj = 0); text(2.5, 4, "\\134")
##
## pltmth> text(3, 4, expression(symbol("\134")))
##
## pltmth> text(1, 5, "perpendicular", adj = 0); text(2.5, 5, "\\136")
##
## pltmth> text(3, 5, expression(symbol("\136")))
##
## pltmth> text(1, 6, "circlemultiply", adj = 0); text(2.5, 6, "\\304")
##
## pltmth> text(3, 6, expression(symbol("\304")))
##
## pltmth> text(1, 7, "circleplus", adj = 0); text(2.5, 7, "\\305")
##
## pltmth> text(3, 7, expression(symbol("\305")))
##
## pltmth> text(1, 8, "emptyset", adj = 0); text(2.5, 8, "\\306")
##
## pltmth> text(3, 8, expression(symbol("\306")))
##
## pltmth> text(1, 9, "angle", adj = 0); text(2.5, 9, "\\320")
##
## pltmth> text(3, 9, expression(symbol("\320")))
##
## pltmth> text(1, 10, "leftangle", adj = 0); text(2.5, 10, "\\341")
##
## pltmth> text(3, 10, expression(symbol("\341")))
##
## pltmth> text(1, 11, "rightangle", adj = 0); text(2.5, 11, "\\361")
##
## pltmth> text(3, 11, expression(symbol("\361")))
x<- 0:20
y <- 0:20
plot(x,y, type="n")
text( 4, 4, expression(paste(alpha)))
## See difference below: quoting prevents math-ization
text( 6, 4, expression(paste("alpha")))
## * is joiner, not multiplication
text( 12, 5, expression(paste(alpha*beta*gamma," alpha beta gamma")))
text( 4, 6, expression(paste(alpha, beta, gamma, sep="")))
text ( 2, 8, expression(frac(1, sigma)))
text ( 9, 2, expression(frac(1, sqrt(pi * sigma^2))*e^{ - frac(1,2) * (x-mu)^2}))
text ( 9, 10, expression(frac(1, sqrt(pi * sigma^2)) * e^{ - phantom(0) *frac(1,2) * phantom(0) * (x-mu)^2}))
text ( 9, 8, expression(italic(frac(1, sqrt(pi * sigma^2)) * e^{ - phantom(0) *frac(1,2) * phantom(0) * (x-mu)^2})))
text (5, 15, paste(expression( alpha * beta), x[1]))
### mtext is for margin text
mtext(expression(hat(alpha)), side=1, at=3, line = 2 )
mtext(expression(widehat(alpha*gamma)), side=1, at=5.5, line = 2)
example(mtext)
##
## mtext> plot(1:10, (-4:5)^2, main = "Parabola Points", xlab = "xlab")
##
## mtext> mtext("10 of them")
##
## mtext> for(s in 1:4)
## mtext+ mtext(paste("mtext(..., line= -1, {side, col, font} = ", s,
## mtext+ ", cex = ", (1+s)/2, ")"), line = -1,
## mtext+ side = s, col = s, font = s, cex = (1+s)/2)
##
## mtext> mtext("mtext(..., line= -2)", line = -2)
##
## mtext> mtext("mtext(..., line= -2, adj = 0)", line = -2, adj = 0)
##
## mtext> ##--- log axis :
## mtext> plot(1:10, exp(1:10), log = "y", main = "log =\"y\"", xlab = "xlab")
##
## mtext> for(s in 1:4) mtext(paste("mtext(...,side=", s ,")"), side = s)
mtext( "crap crap", side=1, line=2)
mtext( "TRUTH", side=1, line=1)
mtext( expression(paste(f(x) == g(h(x)))), side=1, line=2)
##################