How to create the plot of a vector that contains missing values by adding the missing values in base R?



If there are missing values in a vector then the plot of such vector will not have all the values, only the nonβˆ’missing values will be shown. If we want to create the plot by adding the missing values in the plot then we need to define the Xβˆ’axis for the length of the vector and the Yβˆ’axis with the actual vector using cbind but missing values will be omitted as shown in the below example.

Example

 Live Demo

x<βˆ’c(2,5,3,NA,3,5,NA,2,7,6)
plot(x,type="l")

Output

Creating the plot by adding the missing values

Example

plot(na.omit(cbind(x=seq_along(x),y=x)),type="l")

Output

Updated on: 2021-02-05T10:03:42+05:30

361 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements