// 谷村 2005年  4月 14日 木曜日
// 自由に修正加筆してください

COLOR(red){SIZE(25){tkrplot}}

#contents

* tkrplotとは [#n559f7a6]

tkrplotとは、Tk ウィジェットの中にRグラフィックを配置するライブラリである。

* 実例 [#jeadc5e7]
* 実例1 [#jeadc5e7]
 library(tcltk)
 library(tkrplot)
 tt <- tktoplevel()
 bb <- 1
 img <- tkrplot(tt, function() plot(1:20,(1:20)^bb))
 f <- function(...) {
   b <- as.numeric(tclvalue("bb"))
   if (b != bb) {
     bb <<- b
     tkrreplot(img)
   }
 }
 a <- tkscale(tt, command=f, from=0.05, to=2.00, variable="bb",
              showvalue=FALSE, resolution=0.05, orient="horiz")
 tkpack(img,a)

''結果''

&ref(tkrplot.gif);
// x11recで録画しましたが、これってWindow枠やマウスカーソルが記録されない
// のですね。vnc2swfの方がよかったのかな。

例えば、このようにマウスでスクロールして対話的にグラフを表示するようなものを作成できる。

* 実例2 自由度によるt分布の変化を体験する [#l3828ea6]
//2016年12月14日追加

 library(tkrplot)
 tt <- tktoplevel()
 df <- 1
 td <- function() {
     curve(dt(x, df), from = -4, to = 4, xlab = "x",
           ylab = "density", main = "t distribution",
           ylim = c(0, 0.4))
 }
 img <- tkrplot(tt, td)
 f <- function(...){
     d <- as.numeric(tclvalue("df"))
     if(d != df){
         df <<- d
         tkrreplot(img)
     }
 }
 s <- tkscale(tt, command = f, from = 1, to = 20, label="自由度",
              variable = "df",
              showvalue = TRUE, resolution = 1, orient = "horiz")
 tkpack(img, s)

こちらの環境ではtkscale()は文字化けしないが、tkrplot()のxlabやylabは文字化けする。fontの指定などはできない模様。

''結果''

&ref(tdist.gif);

* コメントなど [#c5b0b8c2]

#comment



トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS