[R] circular reference lines in splom

Max Kuhn mxkuhn at gmail.com
Thu Jan 20 05:15:45 CET 2011


Hello everyone,

I'm stumped. I'd like to create a scatterplot matrix with circular
reference lines. Here is an example in 2d:

library(ellipse)

set.seed(1)
dat <- matrix(rnorm(300), ncol = 3)
colnames(dat) <- c("X1", "X2", "X3")
dat <- as.data.frame(dat)
grps <- factor(rep(letters[1:4], 25))

panel.circ <- function(x, y, ...)
  {
    circ1 <- ellipse(diag(rep(1, 2)), t = 1)
    panel.xyplot(circ1[,1], circ1[,2],
                 type = "l",
                 lty = 2)
    circ2 <- ellipse(diag(rep(1, 2)), t = 2)
    panel.xyplot(circ2[,1], circ2[,2],
                 type = "l",
                 lty = 2)
    panel.xyplot(x, y)
  }

xyplot(X2 ~ X1, data = dat,
       panel = panel.circ,
       aspect = 1)

I'd like to to the sample with splom, but with groups.

My latest attempt:

panel.circ2 <- function(x, y, groups, ...)
  {
    circ1 <- ellipse(diag(rep(1, 2)), t = 1)
    panel.xyplot(circ1[,1], circ1[,2],
                 type = "l",
                 lty = 2)
    circ2 <- ellipse(diag(rep(1, 2)), t = 2)
    panel.xyplot(circ2[,1], circ2[,2],
                 type = "l",
                 lty = 2)
    panel.xyplot(x, y, type = "p", groups)
  }



splom(~dat,
      panel = panel.superpose,
      panel.groups = panel.circ2)

produces nothing but warnings:

> warnings()
Warning messages:
1: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'

It does not appear to me that panel.circ2 is even being called.

Thanks,

Max

> sessionInfo()
R version 2.11.1 Patched (2010-09-30 r53356)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] lattice_0.19-11 ellipse_0.3-5

loaded via a namespace (and not attached):
[1] grid_2.11.1  tools_2.11.1



-- 

Max



More information about the R-help mailing list