Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) : plot.new has not been called yet

linear_regression
r

#1

while writing the code for linear regression in R I have used the command abline but I am getting the error" Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, …) :
plot.new has not been called yet "
but I have included plot command in the code

data(airquality)
names(airquality)
plot(Ozone~Solar.R,data=airquality)
mean.Ozone=mean(airquality$Ozone,na.rm=T)
abline(h=mean.Ozone)


#2

I’m not able to recreate the error - the code works normally for me. How are you executing the code: base R (R GUI), RStudio, or something else? Make sure that plot is created before you execute the abline() part.


#3

@hinduja1234 -I think once after you use plot command you close the plot and when you are using the command abline you are getting this error.

Hope this helps!
Regards,
harry