Skip to content

NA values break plot.errors #35

@richardsc

Description

@richardsc

Just discovered this package (after thinking about writing my own) -- it's great! Thanks!

I noticed that xlim and ylim are hard-coded in the NextMethod() call for plot.errors() to be range(x) and range(y).

One problem with this is that it is impossible to control the axis limits of the plot (say, to focus on a region or reverse an axes).

Another issue is that if x or y have NAs they cause plot.errors() to fail:

library(errors)
x <- 1:100
y <- rnorm(x)
y[20] <- NA
errors(x) <- 0
errors(y) <- rnorm(y, sd=0.25)
plot(x, y)
Error in plot.window(...) : need finite 'ylim' values

I don't see why plot.errors() isn't simply written as:

plot.errors <- function(x, y, ...) {
  if (missing(y)) {
    y <- x
    x <- seq_along(x)
  }

  NextMethod()

  if (inherits(x, "errors"))
    graphics::segments(errors_min(x), y, errors_max(x), y)

  if (inherits(y, "errors"))
    graphics::segments(x, errors_min(y), x, errors_max(y))
}

Note that using the na.rm=TRUE argument in range() doesn't help, as it still returns c(NA, NA) for range(y). I assume that this is due to the interaction the base range() function with the errors-class object and it doesn't know what to do with it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions