tkRplot: Tk Rplot With Resizing

Description Usage Arguments Examples

View source: R/functions.R

Description

Displays a plot in a Tk toplevel window.

Usage

1
2
3
tkRplot(W, fun, width = 490, height = 490, ...)
tkRreplot(W, fun, width, height,  ...)
.tkRreplot(W)

Arguments

W

Tk toplevel window

fun

function to produce the plot

width

image width

height

image height

...

additional arguments

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
## Not run: 
#Example 1 without using tkReplot function (tkRplotR version > 0.1.6)
tk_b <- tclVar(1)
tk_x <- tclVar(10)
tk_main <- tclVar('...')

tt0 <- tktoplevel()
tt0 <- tkRplot(tt0, function(...) {
# get values of tclvariables
  x <- .tcl2num(tk_x)
  x <- 1:x
  b <- .tcl2num(tk_b)
  main <- .tcl2String(tk_main)

  plot(
    x,
    x ^ b ,
    col = "#0000ff50",
    xlab = "x",
    ylab = expression(x^b),
    type = "l",
    axes = FALSE,
    lwd = 4)
  title(main = main)
  points(x,
         x ^ b,
         col = "#ff000050",
         pch = 19,
         cex = 2)
  axis(1)
  axis(2)
  box()
})

s01 <- tkscale(
  tt0,
  #command = function(...) .tkRreplot(tt0),
  from = 10,
  to = 60,
  label = 'x',
  variable = tk_x,
  showvalue = TRUE,
  resolution = 1,
  repeatdelay = 200,
  repeatinterval = 100,
  orient = "hor"
)

s02 <- tkscale(
  tt0,
  #command = function(...) .tkRreplot(tt0),
  from = 0.05,
  to = 2.00,
  label = 'b',
  variable = tk_b,
  showvalue = TRUE,
  resolution = 0.01,
  repeatdelay = 200,
  repeatinterval = 100,
  orient = "ver"
)


e01 <- tkentry(tt0,
              textvariable = tk_main,
              validate = 'all', validatecommand="")
tkpack(s02,
       side = "left",
       expand = FALSE,
       #'anchor = "c",
       before = tt0$env$canvas,
       fill = "both")

tkpack(s01,
       side = "bottom",
       expand = FALSE,
       #'anchor = "c",
       before = tt0$env$canvas,
       fill = "both")

tkpack(e01,
       side = "top",
       expand = FALSE,
       #'anchor = "c",
       before = tt0$env$canvas,
       fill = "both")


#Example 2 using tkReplot function (tkRplotR version < 0.1.7)
bb <- 1
tkbb <- tclVar(1)
tt <- tktoplevel()
f <- function(...) {
 b <- as.numeric(tclvalue(tkbb))
   if (b != bb) {
       bb <<- b
           tkRreplot(tt)
             }
     }

tt <- tkRplot(tt, function() {
 x <- 1:20 / 20
   plot(
   x,
   x ^ bb,
   col = "#0000ff50",
       xlab = "x",
           ylab = paste0("x^", bb),
               type = "l",
                   axes = FALSE,
                       lwd = 4)
   title(main = bb)
     points(x,
      x ^ bb,
      col = "#ff000050",
      pch = 19,
      cex = 2)
        axis(1)
        axis(2)
          box()
          })

  s <- tkscale(
       tt,
       command = f,
       from = 0.05,
       to = 2.00,
       variable = tkbb,
       showvalue = TRUE,
       resolution = 0.01,
       repeatdelay = 50,
       repeatinterval = 100,
       orient = "horiz"
       )

       tkpack(s,
       side = "bottom",
       expand = FALSE,
       before = tt$env$canvas,
       fill = "both")


## End(Not run)

tkRplotR documentation built on June 27, 2021, 5:08 p.m.