• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Data Viz with Python and R

Learn to Make Plots in Python and R

  • Home
  • Seaborn
  • Matplotlib
  • ggplot2
  • Altair
  • About
    • Privacy Policy
  • Visualizing Activation Functions in Neural Networks
  • Confusion Matrix Calculator
  • Visualizing Dropout Rate in Neural Network
  • Visualizing Loss Functions in Neural Networks
  • Show Search
Hide Search

How to Turn off “missing values have been dropped” warning message in ggplot2

datavizpyr · October 31, 2023 ·

Last updated on November 3, 2023

In this post, we will learn how to turn off the “missing values” warning message from ggplot2, when making a scatterplot with data containing missing values. geom_point() in ggplot2 gives a warning when it drops missing values from from the dataset it is plotting. Here is example of the warning when geom_point() drops 2 data points while plotting.

Removed 2 rows containing missing values (`geom_point()`)

We will see two examples of how to turn off the warning message. Let us get started by loading tidyverse and palmer penguin dataset for making plots.

library(tidyverse)
library(palmerpenguins)
theme_set(theme_bw(16))

Palmer penguin dataset has missing values. When we try to make a scatter plot as shown below

penguins %>%
  ggplot(aes(x=body_mass_g, 
             y = flipper_length_mm,
             color=species))+
  geom_point()+
  scale_color_brewer(palette ="Dark2" )
ggsave("remove_missing_values_dropped_warning_ggplot.png")

We get the following warning

## Warning: Removed 2 rows containing missing values (`geom_point()`).

Drop NAs from data to avoid the warning message

One approach to get around the warning message “Removed 2 rows containing missing values” is to drop rows containing missing values before plotting using drop_na() function in tidyr.

drop_na() function by default removes a row if there is any NA value. Therefore we will not see the warning message.

penguins %>%
  drop_na() %>%
  ggplot(aes(x=body_mass_g, 
             y = flipper_length_mm,
             color=species))+
  geom_point()+
  scale_color_brewer(palette ="Dark2" )

use na.rm in geom_point() to avoid the warning message

We can actually turn off the warning message that “rows containg missing values have been dropped” by specifying na.rm=TRUE as argument to geom_point() function.

penguins %>%
  drop_na() %>%
  ggplot(aes(x=body_mass_g, 
             y = flipper_length_mm,
             color=species))+
  geom_point(na.rm=TRUE)+
  scale_color_brewer(palette ="Dark2" )

When wsing na.rm=TRUE within geom_point(), ggplot2 takes care of the rows with missing values insterad of us dropping the rows with missing values in the whole dataframe.

Explore the Complete ggplot2 Guide

35+ tutorials with code: scatterplots, boxplots, themes, annotations, facets, and more—tested and beginner-friendly.

Visit the ggplot2 Hub → No fluff—just code and visuals.

Related posts:

Customizing Mean mark to boxplot with ggplot2How To Show Mean Value in Boxplots with ggplot2? Scatterplot with marginal multi-histogram with ggExtraHow To Make Scatterplot with Marginal Histograms in R? ggforce geom_circle(): Annotate with a circleHow To Annotate a Plot with Circle in R Default ThumbnailHow to Make Axis Text Bold in ggplot2

Filed Under: ggplot2, R Tagged With: turn off rows with NAs are remove

Primary Sidebar

Python & R Viz Hubs

  • Seaborn Guide & Cookbook
  • ggplot2 Guide & Cookbook
  • Matplotlib Guide & Cookbook
  • Confusion Matrix Calculator
  • Visualizing Activation Functions
  • Visualizing Dropout
  • Visualizing Loss Functions

Buy Me a Coffee

Copyright © 2026 · Daily Dish Pro on Genesis Framework · WordPress · Log in

Go to mobile version