[R] Suppressing error messages printed in xyplot() with panel function
Adam Zeilinger
zeil0006 at umn.edu
Wed Aug 24 21:30:37 CEST 2011
Hello,
I am using the xyplot() function to create a series of scatterplot
panels with lines of best fit. To draw the lines of best fit for each
panel, I am using a panel function. Here's an example:
> species <- as.character(c(rep(list("A", "B", "A"), 10), "B"))
> year <- as.character(c(rep(list("2009", "2009", "2010"), 10), "2010"))
> x <- rnorm(31, mean = 50, sd = 1)
> y <- 3*x + 20
> ex.data <- data.frame(cbind(species, year, x, y))
> ex.data$x <- as.numeric(ex.data$x)
> ex.data$y <- as.numeric(ex.data$y)
> xyplot(y ~ x|species*year, data = ex.data,
+ panel = function(x, y) {
+ panel.xyplot(x, y, pch=16, col="black")
+ panel.abline(lm(y ~ x))})
With my data set, there are some panels with less than 2 data points.
In these panels, an error message is printed in the panel, something
like: "Error using packet 4 missing value where TRUE/FALSE needed."
In the panels with error messages, I want to keep the panels but
suppress the error message, such that the panel is blank or has only one
datum. How do I do suppress the printing of the error message?
Thanks in advance for your help.
Adam
--
Adam Zeilinger
Conservation Biology Program
University of Minnesota
More information about the R-help
mailing list