[R] histogram method for S4 class.

From: ernesto <ernesto_at_ipimar.pt>
Date: Wed 24 Aug 2005 - 21:26:16 EST


Hi,

I'm trying to develop an histogram method for a class called "FLQuant" which is used by the package FLCore (http://flr-project.org). FLQuant is an extension to "array". There is an as.data.frame method that coerces flquant into a data.frame suitable for lattice plotting. The problem is that when I coerce the object and plot it after it works but if the method is applied within the histogram method it does not work. See the code below (the FLCore package is here
http://prdownloads.sourceforge.net/flr/FLCore_1.0-1.tar.gz?download)

> library(FLCore)

Loading required package: lattice
> data(ple4)
> histogram(~data|year, data=ple4@catch.n)
Error in inherits(x, "factor") : Object "x" not found
> histogram(~data|year, data=as.data.frame(ple4@catch.n))

The catch.n slot is a FLQuant object and the code for histogram is the following

setMethod("histogram", signature(formula="formula", data="FLQuant"),

    function (formula, data = parent.frame(), allow.multiple = is.null(groups) || outer,

        outer = FALSE, auto.key = FALSE, aspect = "fill", panel = "panel.histogram", prepanel = NULL,

        scales = list(), strip = TRUE, groups = NULL, xlab, xlim, ylab, ylim,

        type = c("percent", "count", "density"),
        nint = if (is.factor(x)) length(levels(x)) else
round(log2(length(x)) + 1),
        endpoints = extend.limits(range(x[!is.na(x)]), prop = 0.04),
        breaks = if (is.factor(x)) seq(0.5, length = length(levels(x)) +
1) else do.breaks(endpoints, nint),
        equal.widths = TRUE, drop.unused.levels =
lattice.getOption("drop.unused.levels"), ...,
        default.scales = list(), subscripts = !is.null(groups), subset =
TRUE) {         qdf <- as.data.frame(data)

        histogram(formula, data = qdf, allow.multiple = allow.multiple, outer = outer,

            auto.key = auto.key, aspect = aspect, panel = panel, prepanel = prepanel, scales = scales,

            strip = strip, groups = groups, xlab=xlab, xlim=xlim, ylab=ylab, ylim=ylim, type = type,

            nint = nint, endpoints = endpoints, breaks = breaks, equal.widths = equal.widths,

            drop.unused.levels = drop.unused.levels, ..., default.scales = default.scales,

            subscripts = subscripts, subset = subset)     }
)

Any ideas ?

Thanks

EJ



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Aug 24 21:34:10 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:55 EST