COLOR(red){SIZE(20){グラフィックス参考実例集:数式のプロット}}

タイトル等の注釈に expression, substitute 関数の引数として数式表現を与えることにより数式のプロットが可能になる。使える記号や品位は限られており、数式・記号の完全な制御には pictex ドライバーを用い、latex コードに落し、マニュアルで編集する。

#contents
~
*例1 [#f0c1220a]
 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),
      labels = expression(-pi, -pi/2, 0, pi/2, pi))
#ref(グラフィックス参考実例集:数式のプロット/Rplot1.png, left)

*例2 数式と数値変数の結合 [#k21c3a8e]
 ## How to combine "math" and numeric variables :
 plot(1:10, type="n", xlab="", ylab="", main = "plot math & numbers")
 theta <- 1.23 ; mtext(bquote(hat(theta) == .(theta)), line= .25)
 for(i in 2:9)
     text(i, i+1, substitute(list(xi, eta) == group("(",list(x,y),")"),
                             list(x = i, y = i+1)))
 ## note that both of these use calls rather than expressions.
 ##
 text(1, 10,  "Derivatives:", adj = 0)
 text(1, 9.6, expression(
  "             first: {f * minute}(x) " == {f * minute}(x)), adj = 0)
 text(1, 9.0, expression(
  "     second: {f * second}(x) "        == {f * second}(x)), adj = 0)
#ref(グラフィックス参考実例集:数式のプロット/Rplot2.png, left)
 
 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)
#ref(グラフィックス参考実例集:数式のプロット/Rplot3.png, left)

*例3 いくつかの有用な記号 [#nb6c8d1e]
 ## some other useful symbols
 plot.new(); plot.window(c(0,4), c(15,1))
 text(1, 1, "universal", adj = 0); text(2.5, 1,  "\\042")
 text(3, 1, expression(symbol("\042")))
 text(1, 2, "existential", adj = 0); text(2.5, 2,  "\\044")
 text(3, 2, expression(symbol("\044")))
 text(1, 3, "suchthat", adj = 0); text(2.5, 3,  "\\047")
 text(3, 3, expression(symbol("\047")))
 text(1, 4, "therefore", adj = 0); text(2.5, 4,  "\\134")
 text(3, 4, expression(symbol("\134")))
 text(1, 5, "perpendicular", adj = 0); text(2.5, 5,  "\\136")
 text(3, 5, expression(symbol("\136")))
 text(1, 6, "circlemultiply", adj = 0); text(2.5, 6,  "\\304")
 text(3, 6, expression(symbol("\304")))
 text(1, 7, "circleplus", adj = 0); text(2.5, 7,  "\\305")
 text(3, 7, expression(symbol("\305")))
 text(1, 8, "emptyset", adj = 0); text(2.5, 8,  "\\306")
 text(3, 8, expression(symbol("\306")))
 text(1, 9, "angle", adj = 0); text(2.5, 9,  "\\320")
 text(3, 9, expression(symbol("\320")))
 text(1, 10, "leftangle", adj = 0); text(2.5, 10,  "\\341")
 text(3, 10, expression(symbol("\341")))
 text(1, 11, "rightangle", adj = 0); text(2.5, 11,  "\\361")
 text(3, 11, expression(symbol("\361")))
#ref(グラフィックス参考実例集:数式のプロット/Rplot4.png, left)

* plotmath 機能で扱える数式の一覧 [#fa22b941]

#ref(グラフィックス参考実例集:数式のプロット/Rplot5.png, left)
#ref(グラフィックス参考実例集:数式のプロット/Rplot6.png, left)
#ref(グラフィックス参考実例集:数式のプロット/Rplot7.png, left)
#ref(グラフィックス参考実例集:数式のプロット/Rplot8.png, left)
#ref(グラフィックス参考実例集:数式のプロット/Rplot9.png, left)

|   構文               |        意味  |   構文               |        意味|
|  `x + y'             |         x plus y|  `x*y'               |         juxtapose x and y |
|  `x/y'                |        x forwardslash y  |  `x %+-% y'           |        x plus or minus y |
|  `x %/% y'            |        x  divided by y |  `x %*% y'            |        x times y |
|  `x[i]'               |        x subscript i |  `x^2'                |        x superscript 2 |
|  `paste(x, y, z)'     |        juxtapose x, y, and z | `sqrt(x)'            |        square root of x |
|  `sqrt(x, y)'         |        yth root of x |  `x == y'             |        x equals y |
|  `x != y'             |        x is not equal to y |  `x < y'              |        x is less than y |
|  `x <= y'             |        x is less than or equal to y |  `x > y'              |        x is greater than y |
|  `x >= y'             |        x is greater than or equal to y   |  `x %~~% y'           |        x is approximately equal to y |
|  `x %=~% y'           |        x and y are congruent  |  `x %==% y'           |        x is defined as y |
|  `x %prop% y'         |        x is proportional to y   |  `plain(x)'           |        draw x in normal font |
|  `bold(x)'            |        draw x in bold font  |  `italic(x)'          |        draw x in italic font |
|  `bolditalic(x)'      |        draw x in bolditalic font  |  `list(x, y, z)'      |        comma-separated list |
|  `...'                |        ellipsis (height varies) |  `cdots'             |         ellipsis (vertically centred) |
|  `ldots'             |         ellipsis (at baseline)  |  `x %subset% y'      |         x is a proper subset of y |
|  `x %subseteq% y'    |         x is a subset of y  |  `x %notsubset% y'   |         x is not a subset of y |
|  `x %supset% y'      |         x is a proper superset of y  |  `x %supseteq% y'    |         x is a superset of y |
|  `x %in% y'          |         x is an element of y  |  `x %notin% y'       |         x is not an element of y |
|  `hat(x)'              |       x with a circumflex  |  `tilde(x)'            |       x with a tilde |
|  `dot(x)'               |      x with a dot  |  `ring(x)'              |      x with a ring |
|  `bar(xy)'              |      xy with bar  |  `widehat(xy)'          |      xy with a wide circumflex |
|  `widetilde(xy)'        |      xy with a wide tilde |  `x %<->% y'            |      x double-arrow y |
|  `x %->% y'             |      x right-arrow y   |  `x %<-% y'             |      x left-arrow y |
|  `x %up% y'             |      x up-arrow y |  `x %down% y'           |      x down-arrow y |
|  `x %<=>% y'            |      x is equivalent to y  |  `x %=>% y'             |      x implies y |
|  `x %<=% y'             |      y implies x |  `x %dblup% y'         |       x double-up-arrow y |
|  `x %dbldown% y'       |       x double-down-arrow y |  `alpha' - `omega'      |      Greek symbols|
|  `Alpha' - `Omega'      |      uppercase Greek symbols |  `infinity'             |      infinity symbol |
|  `partialdiff'           |     partial differential symbol   |  `32*degree'             |     32 degrees |
|  `60*minute'           |       60 minutes of angle  |  `30*second'          |        30 seconds of angle |
|  `displaystyle(x)'    |        draw x in normal size (extra spacing) |  `textstyle(x)'        |       draw x in normal size |
|  `scriptstyle(x)'       |      draw x in small size |  `scriptscriptstyle(x)'  |     draw x in very small size |
|  `x ~~ y'                 |    put extra space between x and y  |  `x + phantom(0) + y'      |   leave gap for "0", but don't draw it |
|  `x + over(1, phantom(0))'  |  leave vertical gap for "0" (don't draw) |  `frac(x, y)'            |     x over y |
|  `over(x, y)'            |     x over y |  `atop(x, y)'            |     x over y (no horizontal bar) |
|  `sum(x[i], i==1, n)'    |     sum x[i] for i equals 1 to n |  `prod(plain(P)(X==x), x)' |    product of P(X=x) for all values of x|
|  `integral(f(x)*dx, a, b)'  |  definite integral of f(x) wrt x  |  `union(A[i], i==1, n)'     |  union of A[i] for i equals 1 to n |
|  `intersect(A[i], i==1, n)'  |  intersection of A[i]  |  `lim(f(x), x %->% 0)'      |  limit of f(x) as x tends to 0 |
|  `min(g(x), x > 0)'         |  minimum of g(x) for x greater than 0  |  `inf(S)'                   |  infimum of S |
|  `sup(S)'                  |   supremum of S   |  `x^y + z'                 |   normal operator precedence |
|  `x^(y + z)'               |   visible grouping of operands   |  `x^{y + z}'               |   invisible grouping of operands |
|  `group("(",list(a, b),"]")' | specify left and right delimiters  |  `bgroup("(",atop(x,y),")")' | use scalable delimiters |
|  `group(lceil, x, rceil)'    | special delimiters | | |

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Google
WWW を検索 OKADAJP.ORG を検索