简体   繁体   English

在 Rmarkdown 中添加到 plot 曲线或直线

[英]Add to plot curve or line in Rmarkdown

plot(model$residuals,
abline(h=0,col="red")

when i run abline() function, return this error:当我运行 abline() function 时,返回此错误:

Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...): plot.new has not been called yet int_abline 中的错误(a = a,b = b,h = h,v = v,untf = untf,...):plot.new 尚未被调用

How can i solve it?我该如何解决?

First plot your residuals then call abline seperately:首先 plot 你的残差然后分别调用abline

df <- data.frame(x = 1:10, y = 1:10 + rnorm(10))
model <- lm(y ~ x, data = df)
plot(df$x, model$residuals)
abline(h = 0, col = "red")

Created on 2020-04-27 by the reprex package (v0.3.0)代表 package (v0.3.0) 于 2020 年 4 月 27 日创建

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

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