각 값이 type
인 경우 맞춤 패널 기능을 만들어야합니다. 다행히도 기존의 격자 코드 (이 코드는 panel.xyplot
으로 시작)에서 함수를 자세히 모델링하면 너무 어렵지 않습니다. 예를 들어, 아래의 두 개의 사용자 정의 패널 함수는 많은 코드 행을 포함하지만 작성해야하는 몇 줄 (주석으로 표시) 만 포함합니다.
library(lattice)
library(latticeExtra)
library(gridExtra)
set.seed(100)
data <- data.frame(time=1:24,value=rnorm(24))
## Filled version of xyplot(..., type="S")
a <- xyplot(value~time, data, panel=panel.filled_S)
## Filled version of xyplot(..., type="smooth")
b <- xyplot(value~time, data, panel=panel.filled_smooth)
grid.arrange(a, b, ncol = 2)

을 type="S"
의 작성 버전 : 당신이 패널 기능을 정의하면
과 같이이를 사용, (그림 다음 코드 블록에서 그들을에서 복사)
type="smooth"
의 작성 버전에 대한
## Modeled on code in panel.xyplot, which is called when type=S"
panel.filled_S <-
function(x,y, ...) {
horizontal <- FALSE ## Edited (may not want to hardcode)
ord <- if (horizontal)
sort.list(y)
else sort.list(x)
n <- length(x)
xx <- numeric(2 * n - 1)
yy <- numeric(2 * n - 1)
xx[2 * 1:n - 1] <- x[ord]
yy[2 * 1:n - 1] <- y[ord]
xx[2 * 1:(n - 1)] <- x[ord][-n]
yy[2 * 1:(n - 1)] <- y[ord][-1]
panel.xyarea(x = xx, y = yy, ...) ## Edited
panel.lines(x = xx, y = yy, ...) ## Edited
}
xyplot(value~time, data, panel=panel.filled_S, type="o")
:
## Modeled on code in panel.loess, called by panel.xyplot when type="smooth"
panel.filled_smooth <-
function (x, y, span = 2/3, degree = 1, family = c("symmetric",
"gaussian"), evaluation = 50, lwd = plot.line$lwd, lty = plot.line$lty,
col, col.line = plot.line$col, type, horizontal = FALSE,
..., identifier = "loess")
{
x <- as.numeric(x)
y <- as.numeric(y)
ok <- is.finite(x) & is.finite(y)
if (sum(ok) < 1)
return()
if (!missing(col)) {
if (missing(col.line))
col.line <- col
}
plot.line <- trellis.par.get("plot.line")
if (horizontal) {
smooth <- loess.smooth(y[ok], x[ok], span = span, family = family,
degree = degree, evaluation = evaluation)
panel.lines(x = smooth$y, y = smooth$x, col = col.line,
lty = lty, lwd = lwd, ..., identifier = identifier)
panel.xyarea(smooth$y, smooth$x, ...) ## Edited
}
else {
smooth <- loess.smooth(x[ok], y[ok], span = span, family = family,
degree = degree, evaluation = evaluation)
panel.lines(x = smooth$x, y = smooth$y, col = col.line,
lty = lty, lwd = lwd, ..., identifier = identifier)
panel.xyarea(smooth$x, smooth$y, ...) ## Edited
}
smooth
}
아니요, 여러 가지 ** 격자 ** 기능을 수정하지 않고도 간단하고 완전히 일반적인 방법은 없습니다. 'type = '의 특정 값에 대한 완전히 일반적인 (그러나 단순한) 솔루션에 관심이 있습니까? –
물론, 어딘가에서 시작할 수 있습니다. @Josh –
좋아,'type = "S"'및'type = "smooth"'에 대한 몇 가지 빠른 예제를 정리해 보겠습니다. –