tkrplot

tkrplotとは

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

実例1

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)

結果

tkrplot.gif

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

実例2 自由度によるt分布の変化を体験する

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の指定などはできない模様。

結果

tdist.gif

コメントなど



添付ファイル: filetkrplot.gif 2290件 [詳細] filetdist.gif 1201件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2023-03-25 (土) 11:19:17