- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 warning message “Removed X rows containing missing values” for a column of an R data frame while creating a plot?
If we have missing values/NA in our data frame and create a plot using ggplot2 without excluding those missing values then we get the warning “Removed X rows containing missing values”, here X will be the number of rows for the column that contain NA values. But the plot will be correct because it will be calculated by excluding the NA’s. To avoid this error, we just need to pass the subset of the data frame column that do not contains NA values as shown in the below example.
Consider the below data frame with y column having few NA values −
set.seed(112) x<-sample(0:10,25,replace=TRUE) y<-sample(c(21:25,NA),25,replace=TRUE) df<-data.frame(x,y) df
x y 1 4 21 2 10 NA 3 10 23 4 10 22 5 2 NA 6 1 NA 7 0 25 8 8 NA 9 1 22 10 4 23 11 2 21 12 3 23 13 9 25 14 6 25 15 7 21 16 10 24 17 6 NA 18 6 NA 19 8 NA 20 4 24 21 1 23 22 7 21 23 1 21 24 0 22 25 4 NA
Loading ggplot2 package and creating point chart for x and y columns of df −
Warning message −
Removed 5 rows containing missing values (geom_point) −
Here, we are getting the warning message for missing values.
Creating the point chart for x and y by excluding the NA values −
Output of the plot would be same as shown above but the warning message will not be there −
- How to deal with warning “removed n rows containing missing values” while using ggplot2 in R?
- How to remove rows containing missing value based on a particular column in an R data frame?
- How to deal with warning message `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. in R while creating a histogram?
- How to replace missing values in a column with corresponding values in other column of an R data frame?
- How to replace missing values with median in an R data frame column?
- How to deal with missing column for row names when converting data frame to data.table object in R?
- Find the frequency of unique values and missing values for each column in an R data frame.
- How to convert a column with missing values to binary with 0 for missing values in R?
- How to find the sum of non-missing values in an R data frame column?
- How to select rows based on range of values of a column in an R data frame?
- How to find the percentage of missing values in each column of an R data frame?
- How to find rows in an R data frame that do not have missing values?
- How to subset rows of an R data frame based on duplicate values in a particular column?
- How to replace missing values with row means in an R data frame?
- How to plot rows of a data frame as lines in R?