【问题标题】:Plot generation mid-function for input information用于输入信息的绘图生成中间功能
【发布时间】:2018-07-23 17:02:21
【问题描述】:

我使用具有多个且不断变化的时间戳的大型数据集。结果,我找到了识别数据子集的最简单方法,方法是使用这些图绘制和识别我需要的数据范围。

我想运行一个函数来绘制我的数据子集,然后允许我通过查看绘图来输入一个变量(还没有弄清楚如何自动化这一步)并继续运行该函数。但是,在函数内绘图时,下一行将在绘图生成之前运行 - 因此我看不到它。谁能指出我正确的方向?这是我想做的一个例子:

data.initialization <- function(){
  p = c(1,2,3,4,5)  
  l = c(5,6,7,6,5) #initialize some data

  qplot(p,l)       #plot the data so I can see what it looks like

  x = (readline("Input a value based on the plot: "))  #use the information from looking at the plot to input a value

  y = f(x) #do some more operations with the input variable

} 

【问题讨论】:

  • 澄清一下。我真的很希望它能够独立地包含在 Rstudio 中,这样我就不必生成 PDF 或类似的绘图。最好让绘图直接弹出到绘图窗口的中间功能。
  • qplot 包装在print 语句中
  • @emilliman5 完美运行——太容易了!谢谢。

标签: r function plot rstudio


【解决方案1】:

您需要在 qplot 调用周围添加一个 print() 以获取输出

library(ggplot2)
f <- function(z) {
  as.numeric(z)+2
}

data.initialization <- function(){
  p = c(1,2,3,4,5)  
  l = c(5,6,7,6,5) #initialize some data

  print(qplot(p,l))       #plot the data so I can see what it looks like

  x = (readline("Input a value based on the plot: "))  #use the information from looking at the plot to input a value

  y = f(x) #do some more operations with the input variable
  y
} 

data.initialization()

【讨论】:

    猜你喜欢
    • 2017-09-06
    • 2019-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多