[R] xyplot, type="b"

Benjamin Tyner btyner at gmail.com
Fri Jun 23 04:53:49 CEST 2006


Most clever! I'd completely forgotten about panel.segments.

Paul Murrell wrote:

>Here's one way to vectorize the lines ...
>
>my.panel2 <- function(x, y, cex=1, ...){
>    panel.xyplot(x, y, cex = cex, ...)
>    a <- 0.5 * cex *
>         convertWidth(unit(1, "char"), "native", valueOnly=TRUE)
>    b <- 0.5 * cex *
>         convertHeight(unit(1, "char"), "native",valueOnly=TRUE)
>    dx <- diff(x)
>    dy <- diff(y)
>    f <- 1 / sqrt((dx/a)^2 + (dy/b)^2)
>    n <- length(x)
>    x1 <- x[1:(n-1)] + f*dx
>    x2 <- x[2:n] - f*dx
>    y1 <- y[1:(n-1)] + f*dy
>    y2 <- y[2:n] - f*dy
>    i <- f < 0.5
>    panel.segments(x1[i], y1[i], x2[i], y2[i])
>}
>
>Paul
>



More information about the R-help mailing list