看起来包作者并不容易选择正确地公开它。我们可以编写自己的版本plot.efflist
它在这里完成了大部分工作。这是替代版本
plot.efflist <- function (x, selection, rows, cols, graphics = TRUE,
lattice, ...)
{
lattice <- if (missing(lattice))
list()
else lattice
if (!missing(selection)) {
if (is.character(selection))
selection <- gsub(" ", "", selection)
pp <- plot(x[[selection]], lattice = lattice, ...)
pp$x.scales$tck=c(1,0)
pp$y.scales$tck=c(1,0)
return(pp)
}
effects <- gsub(":", "*", names(x))
neffects <- length(x)
mfrow <- mfrow(neffects)
if (missing(rows) || missing(cols)) {
rows <- mfrow[1]
cols <- mfrow[2]
}
for (i in 1:rows) {
for (j in 1:cols) {
if ((i - 1) * cols + j > neffects)
break
more <- !((i - 1) * cols + j == neffects)
lattice[["array"]] <- list(row = i, col = j,
nrow = rows, ncol = cols, more = more)
pp <- plot(x[[(i - 1) * cols + j]], lattice = lattice,
...)
# hack to turn off opposite side tick marks
pp$x.scales$tck=c(1,0)
pp$y.scales$tck=c(1,0)
print(pp)
}
}
}
environment(plot.efflist) <- asNamespace("effects")
基本上我们只是调用plot.eff
按原样运行,然后修改结果以在绘图之前关闭第二组刻度。
这返回
plot(allEffects(m), rug = FALSE)
或者您也可以尝试这种方法
plot.eff <- function(...) {
pp <- effects:::plot.eff(...)
pp$x.scales$tck=c(1,0)
pp$y.scales$tck=c(1,0)
pp
}
environment(plot.eff) <- asNamespace("effects")
helpenv <- new.env(parent = asNamespace("effects"))
helpenv$plot.eff <- plot.eff
plot.efflist <- effects:::plot.efflist
environment(plot.efflist) <- helpenv
在这里,不仅仅是改变操作的函数efflist
对象,我们改变所有人的行为eff
对象。我们进行重写,但还需要更改efflist
版本首先找到我们的新版本。这种方法使我们不必重复这些函数的任何逻辑,但这确实意味着我们对环境造成了一些混乱。