Quantcast
Viewing all articles
Browse latest Browse all 8

Answer by DiegoJArg for Explain ggplot2 warning: "Removed k rows containing missing values"

I know this question already has an answer, but this is another possible solution for you. As you don't provide a sample code, I couldn't know for sure.

If you just want to get rid of it, that implies to me that you are OK with the output. Then you can try the following:

  • Add na.rm=TRUE to geom_something like : geom_line(..., na.rm=TRUE )

This explicitly tells geom_line (and geom_path) that is OK to remove NA values.

Analyzing the warning message:

Warning of: Removed k rows containing missing values (geom_path)

This tells you mainly 3 things:

  • geom_path is being called by another geom_something which is firing the warning.
  • It already removed k rows. So if the output is as desired, then you want those rows removed.
  • The reason for removal is that some values ARE missing (NA).

What the warning doesn't tells you is WHY those rows have missing (NA) values, that only you may know.

An usual reason comes from setting limits to the scale. Like scale_x_datetime or scale_y_continuous.

This makes sense as (X,Y) pairs, to be drawn, requires not to be NA.

When you set the X scale to larger values where there is no Y, OR your Y data is NA. You get (X,Y) points where one of both is NA.

You may want to set a larger scale for a different number of reasons, but ggplot will always find that there isn't an associated Y value, and it makes sense to fire a warning instead of an error.

Have a nice day.


Viewing all articles
Browse latest Browse all 8

Trending Articles