[R] qplot (ggplot2) faceting histogram with missing values

From: Ista Zahn <istazahn_at_gmail.com>
Date: Mon, 03 Mar 2008 20:10:14 -0500


Hi,
I've run into a difficulty with qplot function (in the ggplot2 package). I can facet histograms even when the faceting variable contains missing values, but only so long as the faceting variable is not a factor.

Example:

y1 <- rnorm(10)
x1 <- c(rep(1,5), rep(2,4), NA)
x2 <- factor(c(rep(1,5), rep(2,4), NA))

library(ggplot2)
qplot(y1, geom = "histogram", facets = x1 ~.)# this works qplot(y1, geom = "histogram", facets = x2 ~.)# this doesn't work Error in if (is.null(data) || nrow(data) == 0) return() :

   missing value where TRUE/FALSE needed

This is with ggplot2_0.5.7, R version 2.6.2, on OS X 10.5.2.

Not that this is terribly hard to work around, for example by converting the factor to a vector or simply deleting missing values. I'm mostly just curious about why it doesn't work.

By the way, I really like ggplot2, though I must admit I'm struggling a bit to understand how it really works (I mostly use qplot). Thanks for making this great package available. -Ista



R-help_at_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. Received on Tue 04 Mar 2008 - 01:14:07 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 04 Mar 2008 - 04:30:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive