How to deal with error invalid xlim value in base R plot?


The error invalid xlim value occurs when we incorrectly provide the xlim values, these values are not used in sequence, we just need to provide first and the last value. For Example, if we want to create a point chart of 1 to 5 with xlim having values between -5 to 15 then we can use the command as follows −

plot(1:5,xlim=c(-5:15))

Example

Add the following code to the above command −

plot(1:10)

Output

If you execute the above given command, it generates the following Output −

Add the following code to the above snippet −

plot(1:10)
plot(1:10,xlim=c(-15:15))
Error in plot.window(...) : invalid 'xlim' value

Correct:

plot(1:10,xlim=c(-15,15))

Output

If you execute all the above given snippets as a single program, it generates the following Output −

Updated on: 02-Nov-2021

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements