Dear all,

I do not fully understand how ggplot2 handles NAs. See the following example:

library(ggplot2)
x <- rnorm(150)
g <- as.factor(c(rep(c(0,1,NA),50)))
mydf <- data.frame(x,g)

m <- ggplot(aes(x = x, group = g, color = g), data = mydf)
m + geom_density()


How do I get rid of the NAs (i.e. the blue colored curve)?

I thought

## m <- ggplot(aes(x = x, group = g, color = g, na.rm = TRUE),
## data = mydf)
## m + geom_density()

or

## m <- ggplot(aes(x = x, group = g, color = g), data = mydf)
## m + geom_density()
## m + stat_density(na.rm = TRUE)

etc.

would solve my problem but to no avail.


Thanks for your help,

Bernd

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to