- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to deal with the error “Error in int_abline---plot.new has not been called yet” in R?
The above error means plot is not being created yet hence abline function cannot be used to draw anything on the plot. Therefore, a plot needs to be created first to use abline function for creating a line or any other thing. Mostly, abline is used to create regression line on the plot, thus we need to create a scatterplot first before using abline.
Example
Consider the below data frame −
x<−rnorm(20,102,5.24) y<−rnorm(20,520,3.27) df<−data.frame(x,y) df
Output
x y 1 107.51245 522.3463 2 100.57137 518.9318 3 100.34198 524.1936 4 102.76870 518.2373 5 107.25869 522.0996 6 107.69508 518.5361 7 96.27562 517.9655 8 104.50759 525.0626 9 105.81623 521.5471 10 97.87036 515.1908 11 109.68729 522.7743 12 103.56346 514.5040 13 103.10188 519.9344 14 94.66500 521.0429 15 103.24753 516.2220 16 107.26232 522.1620 17 104.56150 519.0338 18 101.41522 521.0844 19 103.51826 519.5297 20 100.20963 518.9124
Example
abline(lm(y~x))
Output
Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) : plot.new has not been called yet
To use abline, we first need to create the plot, hence it can be done as shown below −
Example
plot(y~x,data=df)
Output
Creating regression line using abline −
Example
abline(lm(y~x))
Output
- Related Articles
- How to deal with “could not find function” error in R?
- How to deal with error “Error in eval(predvars, data, env) : numeric 'envir' arg not of length one” in R?
- How to deal with error invalid xlim value in base R plot?
- How to deal with error “Error in shapiro.test(…) : sample size must be between 3 and 5000” in R?
- How to deal with error “$ operator is invalid for atomic vectors” in R?
- How to deal with error “undefined columns selected” while subsetting data in R?
- How to deal with error “undefined columns selected when subsetting data frame” in R?
- How to deal with glm.fit error “NA/NaN/Inf” for logistic regression model in R?
- How to deal with Error: stat_count() can only have an x or y aesthetic in R?
- How to deal with error “var(x) : Calling var(x) on a factor x is defunct.” in R?
- How to fix getImageData() error ‘The canvas has been tainted by cross-origin data’ in HTML?
- How to find the standard error of mean in R?
- Bootstrap .has-error class
- How has the Walmart-Flipkart deal been beneficial for the end user?
- How to write custom Python Exceptions with Error Codes and Error Messages?

Advertisements