Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

na.rm have no effect in geom_col with position_stack #3532

Closed
dracodoc opened this issue Sep 18, 2019 · 6 comments · Fixed by #5519
Closed

na.rm have no effect in geom_col with position_stack #3532

dracodoc opened this issue Sep 18, 2019 · 6 comments · Fixed by #5519
Labels
bug an unexpected problem or unintended behavior positions 🥇

Comments

@dracodoc
Copy link

Usually na.rm = TRUE will hide the warnings of removing NAs. However when using position_stack with geom_col, the warning cannot be turned off.

df <- data.frame(x = 1:20, value = c(rep(NA, 10), rep(2, 10)))
# this don't have warnings
ggplot(df, aes(x, value)) +
  geom_point(na.rm = TRUE)

# this have warnings
ggplot(df, aes(x, value)) +
  geom_col(na.rm = TRUE)
# Warning message:
# Removed 10 rows containing missing values (position_stack). 

It seemed that the other usage of remove_missing in geom_* take the na.rm parameter, but position_stack doesn't take it as parameter thus no way to hide the warning. Maybe position_stack was supposed to take cleaned data from geom_col too.

R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

ggplot2_3.2.1
@thomasp85
Copy link
Member

@hadley will you be ok with remove_missing() in position_stack() being silent. I don't think it makes sense to include an argument controlling it as the other positions doesn't have this behaviour...

@hadley
Copy link
Member

hadley commented Oct 1, 2019

Hmmm, wouldn't that be inconsistent with other geoms? Then the missings would just be silently removed.

@thomasp85
Copy link
Member

thomasp85 commented Oct 1, 2019

The geom still implements handle_na(). Optimally the position shouldn't do it as well, but if that is not possible it should at least be silent IMO

@hadley
Copy link
Member

hadley commented Oct 1, 2019

Ok, makes sense.

@thomasp85 thomasp85 added bug an unexpected problem or unintended behavior positions 🥇 labels Jan 21, 2020
@thomasp85 thomasp85 added this to the ggplot2 3.3.4 milestone Mar 25, 2021
@thomasp85
Copy link
Member

Hmm... this is actually less obvious. Since the position is calculated before then handle_na() call in the geom there won't be any warning emitted by the geom because NA's have been silently removed by the position...

I can't really see this being handled gracefully, but we can add a switch to the position so that it can be silenced at least

@dryguy
Copy link

dryguy commented May 1, 2021

I'm seeing a similar issue with geom_area().

dat <- data.frame(x = c(1, 2, 3, 4), y = c(1, 2, 3, NA))

# The NA causes geom_area() to give a warning
ggplot() +
  geom_area(data = dat,
            mapping = aes(x = x, y = y))
# Warning message:
#  Removed 1 rows containing missing values (position_stack). 

# However, adding na.rm = TRUE still gives a warning
ggplot() +
  geom_area(data = dat,
            mapping = aes(x = x, y = y),
            na.rm = TRUE)
# Warning message:
#  Removed 1 rows containing missing values (position_stack). 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior positions 🥇
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants