[R] RWiki, tcltk and plot

Alberto Monteiro albmont at centroin.com.br
Fri Mar 30 21:28:14 CEST 2007


I think I - almost - got the knack for GUI programming using the
tcltk library. Maybe I will update the RWiki with this:

#
#################################################
#

library(tcltk)

#
# Create some matrix - nothing about tcltk here
#
matrix <- cbind(rnorm(100), rpois(100, lambda=10), 
  runif(100), rt(100, df=2), rt(100, df=4))

colnames(matrix) <- c("Normal", "Poisson (lambda=10)", 
  "U(0,1)", "Student t (nu=2)", "Student t (nu=4)")

#
# Now comes the interesting part
#
tt <- tktoplevel()
tkwm.title(tt, "A bunch of distributions")
dist.widget <- NULL
plot.widget <- NULL
for (i in 1:length(colnames(matrix))) {
  dist.widget[[i]] <- tklabel(tt, text=(colnames(matrix))[i])
  plot.widget[[i]] <- local({
    n <- i
    tkbutton(tt, text="PLOT", command=function() plot(matrix[,n]))
  })
  tkgrid(dist.widget[[i]], row=i-1)
  tkgrid(plot.widget[[i]], row=i-1, column=1)
}

#
# Game over - click and watch !!!
#
###############################################
#

My question: is there any way to integrate the plot part into
a tcltk window?

Alberto Monteiro



More information about the R-help mailing list