0

I am looking for a way to create plots inside a tcltk window, i want the window to first read some files, then perform some functions on the data and then create plots (preferably in a new window which allows saving).

I am new to tcltk but i want to use it in order for the script to be run and used by users not familiar with the code. I need it to use ggplot2 mostly for the ease of using maps inside the plots.

i tried adjusting the example from the following link to use ggplot2 plots but it shows nothing. http://www.sciviews.org/recipes/tcltk/TclTk-plotting/

i don't need the graphs to be affected by the user's actions, only by the data that he chooses.

i know shiny is the preferred method for easy GUI builds but it has a file size limitation i am trying to avoid.

Dror Bogin
  • 453
  • 4
  • 13

1 Answers1

1

This modification of the code in the link in the question works for me:

library(ggplot2)
library(tcltk2)
library(tkrplot)

hscale <- 1.5    # Horizontal scaling
vscale <- 1.5    # Vertical scaling
plotTk <- function() {
  x <- -100:100
  y <- x^2
  p <- ggplot(data.frame(x, y), aes(x, y)) + geom_point()
  plot(p)
}
win1 <- tktoplevel()
tktitle(win1) <- "A parabola"
win1$env$plot <- tkrplot(win1, fun = plotTk,
  hscale = hscale, vscale = vscale)
tkgrid(win1$env$plot)

screenshot

G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341