[R] qplot (ggplot2) faceting histogram with missing values
Ista Zahn
istazahn at gmail.com
Tue Mar 4 02:10:14 CET 2008
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
More information about the R-help
mailing list