How to display only the first two "plot (model)" plots in script mode?

I have a script that essentially boils down to

model <- lm(d$o ~ d$t * d$w)
plot(model)

      

When I run these commands interactively (RStudio) plot

will create four graphs. The user should go to the next graph by pressing enter.

Now I want to run commands in (almost) non-interactive mode and a command plot

to only display the first two plots. The user of the script will of course still need to click or press enter after the R environment displays the first and second graphics.

How could I achieve this?

Edit

It has been suggested that I am using a parameter which

(described in ?plot.lm

). However, if I change the relevant line to

plot(model, which=1)

      

script breaks off with

Error in box(...) : invalid 'which' argument
Calls: plot -> plot.default -> localBox -> box
In addition: Warning messages:
1: In plot.window(...) : "which" is not a graphical parameter
2: In plot.xy(xy, type, ...) : "which" is not a graphical parameter
3: In axis(side = side, at = at, labels = labels, ...) :
  "which" is not a graphical parameter
4: In axis(side = side, at = at, labels = labels, ...) :
  "which" is not a graphical parameter
Execution halted

      

+3


source to share


2 answers


Try the following:

plot(model, which=1:2). 

      



This worked for me.

+2


source


We do not know your details. But it works!

n=50
d=data.frame(o=rnorm(n,10,3),t=1:n,w=rep(c("A","B","C"),length.out=n))
model <- lm(d$o ~ d$t * d$w)
plot(model)
op=par(mfrow=c(2,2))
for(i in 1:4)plot(model, which=i)
par(op)

      



enter image description here

0


source







All Articles