How to pause for each plot when running R function -
first, need effects
, lme4
packages run scripts below with
library(effects) library(lme4)
i have following script
devasknewpage(ask=true) fm8 <- lmer(reaction ~ 1 + days + (1 + days|subject), sleepstudy, reml = 0, verbose = true) plot(effect("day",fm8)) qqmath(ranef(fm8))
if run script manually, r asks click or enter next page
after each graph. when run following function,
somefunc<-function () { devasknewpage(ask=true) fm8 <- lmer(reaction ~ 1 + days + (1 + days|subject), sleepstudy, reml = 0, verbose = true) plot(effect("day",fm8)) qqmath(ranef(fm8)) }
r asks click or enter next page
last plot. how can make ask each plot in function?
if plotting them acceptable, might try this:
library(gridextra) somefunc<-function () { fm8 <- lmer(reaction ~ 1 + days + (1 + days|subject), sleepstudy, reml = 0, verbose = true) p1 <- plot(effect("day",fm8)) p2 <- qqmath(ranef(fm8))$subject class(p1) <- 'trellis' grid.arrange(p1,p2,nrow = 2) }
the effects package messes class of resulting plot, confuses grid.arrange
, had change back. feel grid.arrange
ought more clever that.
i can speculate what's going wrong devasknewpage
. effect
plotting code pretty elaborate. it's quite possible manipulating graphics device in way overrides setting.
edit
i'm bit surprised, ben bolker's comment right (i.e. version/example of r faq 7.22, "why lattice/trellis graphics not work?", because effects
package calls lattice::xyplot
internally). works op's asked:
somefunc<-function () { devasknewpage(ask=true) fm8 <- lmer(reaction ~ 1 + days + (1 + days|subject), sleepstudy, reml = 0, verbose = true) p1 <- plot(effect("day",fm8)) p2 <- qqmath(ranef(fm8))$subject print(p1) print(p2) }
Comments
Post a Comment