Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Setting `xlim` or `ylim` to values that crop data leads to a confusing warning message #2158

Open
MilesMcBain opened this Issue Jun 14, 2017 · 1 comment

Comments

Projects
None yet
2 participants

If data lie outside the bounds set by xlim and ylim the warning issued is:

Warning: Removed # rows containing missing values

This was misinterpreted by a beginner I was helping as an assertion that there were missing data in their dataframe. I think we can make the message more specific in this case, something like:

Warning: Removed # rows containing data outside plot limits.

A reprex:

library(ggplot2)
a <- data.frame(x = 1:3, y = 1:3)
ggplot(a, aes(x = x, y = y)) + 
  geom_point() +
  xlim(0,2) + 
  ylim(0,2)
#> Warning: Removed 1 rows containing missing values (geom_point).

Collaborator

karawoo commented Jun 14, 2017

Setting limits on a scale changes the underlying data and replaces values outside the limits with NAs, hence that message. These are then treated the same as any NAs in the original data, so it may not be easy to tell which NAs were always there and which were introduced by setting the limits, but I can look into it.

Another option that produces the same plot with no warning is:

ggplot(a, aes(x = x, y = y)) +
  geom_point() +
  coord_cartesian(xlim = c(0, 2), ylim = c(0, 2))

But I agree that the message is confusing to beginners, who are also probably more likely to know about xlim and ylim than coord_cartesian.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment