[R] xyplot, type="b"

Benjamin Tyner btyner at gmail.com
Wed Jun 21 21:20:57 CEST 2006


Yes, this does work as long as the data are spaced far enough apart. If
you peek inside ./main/plot.c, you will find the function 'do_plot_xy'
which provides the functionality I desire for standard graphics. A
down-and-dirty implementation for lattice might be along the lines of

my.panel <- function(x, y, ...){
panel.xyplot(x, y, ...)
d <- 0.5 # for now, should be half the size of 'cex'
xold <- NA
yold <- NA
for(i in 1:length(x)){
xx <- x[i]
yy <- y[i]
f <- d / sqrt(xx * xx + yy * yy)
if(f < 0.5){
# just a kludge for now, would really want to use grid.lines or some such
panel.lines(x = c(xold + f * (xx - xold), xx + f * (xold - xx)),
y = c(yold + f * (yy - yold), yy + f * (yold - yy)))
}
xold <- xx
yold <- yy
}
}

Unfortunately this is not quite right; to do it correctly it seems one
has to address two problems:

1. how to get the size of the default 'cex' to use for 'd' (do_xy_plot uses 'GConvertYUnits' to accomplish this)
2. figure out how to achieve the same effect as what 'GConvert(&xx, &yy, USER, INCHES, dd)' does in do_xy_plot. Otherwise, the gap sizes are not constant.

(1) sounds easy but I don't know the answer offhand. (2) seems more subtle. Any suggestions would be greatly appreciated.

Ben


Sundar Dorai-Raj wrote:

>I think Paul's suggestion works if you use:
>
>  panel.points(x, y, col = "white", cex = 1.5, pch = 16, ...)
>
>instead of the default background color. For me
>trellis.par.get("background")$col returns "transparent".
>
>HTH,
>
>--sundar
>
>  
>



More information about the R-help mailing list