[R] Suppressing error messages printed in xyplot() with panel function
Dennis Murphy
djmuser at gmail.com
Thu Aug 25 04:50:57 CEST 2011
Hi:
Here's one way out:
xyplot(y ~ x|species*year, data = ex.data, type = c('p', 'r'))
type = is a very useful argument to know in xyplot(). See p.75 of the
Lattice book.
HTH,
Dennis
On Wed, Aug 24, 2011 at 12:30 PM, Adam Zeilinger <zeil0006 at umn.edu> wrote:
> 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
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list