2

I am trying to understand how ggplot2's geom_bar treats NAs. The help file says:

library(ggplot2)
?geom_bar

na.rm: If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

I am trying it out:

md <- data.frame(a = c(letters[1:5], letters[1:4], letters[1:3], rep(NA, 3)))
str(md); levels(md$a)

ggplot(data = md, mapping = aes(x = a)) +
  geom_bar(na.rm = F)

It runs without warnings and generates counts for each factor level AS WELL AS the NAs. Makes sense.

Now, I don't want the NAs to be counted. So, I run:

ggplot(data = md, mapping = aes(x = a)) +
  geom_bar(na.rm = T)

But I still have NAs in the picture. Why? What am I missing?

Thank you!

user3245256
  • 1,842
  • 4
  • 24
  • 51
  • To clarify: my question is not about "who could I exclude NAs from being counted" - I know how to do that. My question is: Why na.rm = T is not working for geom_bar in this case? – user3245256 Jul 27 '17 at 14:49

1 Answers1

-1

Its a bug that doses not remove the character case. It's discussed here.

Eric Fail
  • 8,191
  • 8
  • 72
  • 128