To detect the rows that were removed by ggplot2 due to missing values, you can first use the na.omit()
function to remove all rows with missing values from your dataset before creating the plot.
Afterwards you can compare the original dataset to the one with the missing values removed to see which rows were removed and assess whether or not they are impactful to your analysis.
To compare the original dataset to the one with missing values removed, you can use the setdiff()
function from the base R package. This function will return the rows that are present in one dataset but not the other. Documentation
For example, if you have a dataset called df and you create a new dataset called df_clean using the na.omit()
function, you can use setdiff()
like this to find the rows that were removed:
df_clean<- na.omit(df)
setdiff(df, df_clean )