r-输入信息的绘图生成中间函数



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

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

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
} 

您需要在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()

最新更新