문제

Basic Information of my Laptop:

SO: Windows 7 x64
R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"

Problem:

When i run the following code:

x <- rnorm (100)
z <- z + rnorm(100)
f <- gl(2,50,labels =c("Groups 1" , "Groups 2"))
xyplot (z ~ x | f,
    panel = function (x, z, ...) {
      panel.xyplot(x,z, ...)
      panel.abline(h = median(z),
                   lty=2
                   )
    })

What I obtain is no error on console but not graph either, instead of the graph receive two empty graph boxes with inside this error:

 "error using packet 2, argument "z" in missing, with no defaults"

But in the enviroment "z" exist and it is valid!

If I run the script with y instead of z this run as intended, two graph are plotted one aside another(the code works). What is happening here?

도움이 되었습니까?

해결책

Panel functions are passed coordinates x and y, from the notation y ~ x. Hence you write your panel function in terms of those arguments, not the names of your own data objects passed to those arguments. Then it works:

x <- rnorm (100)
z <- x + rnorm(100)
f <- gl(2,50,labels =c("Groups 1" , "Groups 2"))
df <- data.frame(x = x, z = z, f = f) ## I prefer objects in data frames
xyplot (z ~ x | f, data = df,
    panel = function (x, y, ...) {
      panel.xyplot(x, y, ...)
      panel.abline(h = median(y),
                   lty=2
                   )
    })
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top