[R] Problem with llines in lattice

From: John Fox <jfox_at_mcmaster.ca>
Date: Sun 30 Oct 2005 - 06:13:28 EST


Dear r-help list members,

I'm experiencing problems getting type="b" (or "o" or "c") to work in llines(). Try, e.g., the following scaled-down example:

x <- factor(c("a", "b", "a", "b"))
y <- c(1,2,1,2)
z <- factor(c("A", "A", "B", "B"))

symbols <- 1:2
lines <- 1:2
colors <- 1:2
zvals <- levels(z)
xyplot(y~x|z, panel = function(x, y, subscripts, ...) {

    for (i in 1:length(zvals)) {

        sub <- z[subscripts] == zvals[i]
        llines(x[sub], y[sub], lwd = 2, type = "b", 
          col = colors[i], pch = symbols[i], lty = lines[i])
        }

})
    

Only the lines (properly coloured with correct line types) appear, but no symbols are plotted. On the other hand, if I call llines() with type="l" and type="p" separately in the panel function, both lines and points appear:

xyplot(y~x|z, panel = function(x, y, subscripts, ...) {

    for (i in 1:length(zvals)) {

        sub <- z[subscripts] == zvals[i]
        llines(x[sub], y[sub], lwd = 2, type = "p", 
          col = colors[i], pch = symbols[i], lty = lines[i])
        llines(x[sub], y[sub], lwd = 2, type = "l", 
          col = colors[i], pch = symbols[i], lty = lines[i])
        }

})
    

I've looked at both the documentation and code for llines() and lplot.xy(), which llines() calls, and don't see the source of the problem.

I'm using R 2.2.0 under Windows XP. I'm pretty sure that this used to work, but I got the same problem in R 2.1.1 when I tried it there.

Any help would be appreciated.

Thanks,
 John



John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox

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 Sun Oct 30 06:25:51 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:53 EST