Although you call function plot()
, actually it calls function plot.eff()
and it is lattice plot and so par()
argument is ignored. One solution is to use function allEffects()
and then plot()
. This will call function plot.efflist()
. With this function you do not need for loop because all plots are made automatically.
effLogitFrogs <- allEffects(predictorName, logitFrogs)
plot(effLogitFrogs)
EDIT - solution with for loop
There is "ugly" solution to use with for()
loop. For this we need also package grid
. First, make as variables number of rows and columns (now it works only with 1 or 2 columns). Then grid.newpage()
and pushViewport()
set graphical window.
Predictor names are stored in vector outside the loop. Using functions pushViewport()
and popViewport()
all plots are put in the same graphical window.
library(lattice)
library(grid)
n.col=2
n.row= 4
grid.newpage()
pushViewport(viewport(layout = grid.layout(n.row,n.col)))
predictorName <- attr(logitFrogs$terms, "term.labels")
for (i in 1:length(predictorName)) {
print(predictorName[i])
effLogitFrogs <- effect(predictorName[i], logitFrogs)
pushViewport(viewport(layout.pos.col=ceiling(i/n.row), layout.pos.row=ifelse(i-n.row<=0,i,i-n.row)))
p<-plot(effLogitFrogs)
print(p,newpage=FALSE)
popViewport(1)
}