From: Ola Caster <ola.caster_at_gmail.com>

Date: Mon, 12 May 2008 10:44:13 +0200

}

}

<environment: namespace:lattice>

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. Received on Mon 12 May 2008 - 08:49:11 GMT

Date: Mon, 12 May 2008 10:44:13 +0200

Dear all,

It's fairly straightforward to plot cumulative histograms using the hist() function. You do something like:

h <- hist(rnorm(100), plot=FALSE)

h$counts<- cumsum(h$counts)

plot(h)

However, I have failed to find any example where this is done using the lattice histogram() function. I realize I need to slightly alter the panel function panel.histogram. Specifially I would like to add the following line in red, just like I did above:

function (x, breaks, equal.widths = TRUE, type = "density", nint = round(log2(length(x)) +

1), alpha = plot.polygon$alpha, col = plot.polygon$col, border = plot.polygon$border,

lty = plot.polygon$lty, lwd = plot.polygon$lwd, ...) {

plot.polygon <- trellis.par.get("plot.polygon") xscale <- current.panel.limits()$xlim panel.lines(x = xscale[1] + diff(xscale) * c(0.05, 0.95),

y = c(0, 0), col = border, lty = lty, lwd = lwd, alpha = alpha) if (length(x) > 0) {

if (is.null(breaks)) { breaks <- if (is.factor(x)) seq_len(1 + nlevels(x)) - 0.5 else if (equal.widths) do.breaks(range(x, finite = TRUE), nint) else quantile(x, 0:nint/nint, na.rm = TRUE)

}

h <- hist.constructor(x, breaks = breaks, ...) h$counts<- cumsum(h$counts) y <- if (type == "count") h$counts else if (type == "percent") 100 * h$counts/length(x) else h$intensities breaks <- h$breaks nb <- length(breaks) if (length(y) != nb - 1) warning("problem with 'hist' computations") if (nb > 1) { panel.rect(x = breaks[-nb], y = 0, height = y, width = diff(breaks), col = col, alpha = alpha, border = border, lty = lty, lwd = lwd, just = c("left", "bottom"))

}

}

}

<environment: namespace:lattice>

My problem is I'm too unexperienced in handling these panel functions to achieve this. Simply copying the panel function, appending the line, and giving it another name obviously doesn't work (it won't find the function hist.constructor). I would very much appreciate help on how this could be done, or some other way to draw cumulative lattice histograms.

Thanks in advance,

Ola Caster

[[alternative HTML version deleted]]

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. Received on Mon 12 May 2008 - 08:49:11 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Mon 12 May 2008 - 10:30:41 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*