我正在收集一段时间内的数据,我想在同一个图上进行两项研究。对我来说,问题是随着时间的推移如何收集数据并将其添加到绘图中的顺序。举例来说,以下代码将同一组随机值绘制两次,并在每个研究中添加两行:
# 2 figures arranged in 2 rows
par(mfrow=c(2,1))
set.seed(123)
A = sample(seq(from = -2, to = 2, by = 0.1), size = 10, replace = TRUE)
plot(seq(1:10),A, main="Plot 1")
abline(1.2,0, col="red") #First line added
abline(-0.3,0, col="blue") #Third line added
plot(seq(1:10),A, main="Plot 2")
abline(0.7,0, col="green") #Second line added
abline(-0.5,0, col="purple") #Fourth line added
我需要做的是在开始时执行两个绘图命令,然后按照红、绿、蓝、紫的顺序执行添加 4 行。即在顶部研究中添加一条线,在底部研究中添加一条线,并在两个研究之间交替出现新数据。即 - 我希望代码执行如下:
plot(seq(1:10),A, main="Plot 1")
plot(seq(1:10),A, main="Plot 2")
#Wait awhile
abline(1.2,0, col="red") #First line added
abline(0.7,0, col="green") #Second line added
#Wait awhile
abline(-0.3,0, col="blue") #Third line added
abline(-0.5,0, col="purple") #Fourth line added
我如何在 R 中做到这一点,希望使用绘图而不是更深奥的绘图库之一。