简体   繁体   English

在tcltk窗口中绘制ggplot2和ggmap

[英]Plotting ggplot2 and ggmap in tcltk window

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). 我正在寻找一种在tcltk窗口中创建图的方法,我希望该窗口先读取一些文件,然后对数据执行某些功能,然后创建图(最好在一个允许保存的新窗口中)。

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. 我是tcltk的新手,但是我想使用它来使脚本由不熟悉代码的用户运行和使用。 I need it to use ggplot2 mostly for the ease of using maps inside the plots. 我主要需要使用ggplot2来简化在绘图内使用地图的过程。

i tried adjusting the example from the following link to use ggplot2 plots but it shows nothing. 我尝试从以下链接调整示例以使用ggplot2绘图,但未显示任何内容。 http://www.sciviews.org/recipes/tcltk/TclTk-plotting/ 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. 我知道发亮是易于GUI构建的首选方法,但它有文件大小限制,我正努力避免。

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)

截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM