Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在R in图中动态指示组_R - Fatal编程技术网

如何在R in图中动态指示组

如何在R in图中动态指示组,r,R,这是我的数据 x = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22) y = c(1, 6, 2, 5, 4, 7, 9, 6, 8, 4, 5, 6, 5, 5, 6, 7, 5, 8, 9, 5, 4, 7) plot(x, y) fit <- lm(y ~ x) fit abline(fit, col = "black", lwd = "1") x=c(1

这是我的数据

x = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
  17, 18, 19, 20, 21, 22)
y = c(1, 6, 2, 5, 4, 7, 9, 6, 8, 4, 5, 6, 5, 5, 6, 7, 5, 8, 9, 
  5, 4, 7)

plot(x, y)
fit <- lm(y ~ x)
fit
abline(fit, col = "black", lwd = "1")
x=c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,
17, 18, 19, 20, 21, 22)
y=c(1,6,2,5,4,7,9,6,8,4,5,6,5,5,6,7,5,8,9,
5, 4, 7)
绘图(x,y)

拟合您可以使用
predict
获得每个x处的拟合值,然后对观测值和拟合值进行逻辑比较,以测试它们是否在直线上方或下方。然后根据此逻辑比较设置打印的颜色

prediction <- predict(fit)
colors<-ifelse(y>prediction,1,2)
plot(x,y,col=colors)
abline(fit, col= "black",lwd="1")

predict您可以使用
predict
获得每个x处的拟合值,然后对观测值和拟合值进行逻辑比较,以测试它们是否在直线上方或下方。然后根据此逻辑比较设置打印的颜色

prediction <- predict(fit)
colors<-ifelse(y>prediction,1,2)
plot(x,y,col=colors)
abline(fit, col= "black",lwd="1")

prediction谢谢,我怎样才能保存这两个组?在不同的数据中
以上预测]
以下谢谢,我如何保存这两个组?在不同的数据中
以上预测]
以下