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
qplot (ggplot2) faceting histogram with missing values
2 messages · Ista Zahn, Hadley Wickham
Hi Ista, That's a bug, and will be fixed in the next version (hopefully to be released in the next couple of days) Hadley
On Mon, Mar 3, 2008 at 7:10 PM, Ista Zahn <istazahn at gmail.com> wrote:
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.