如何更改回归图功能的代码?

Nic*_*cki -1 plot regression r

我想在R中绘制多个图形。但是,我不想使用par()或layout()函数。我想通过按Enter来更改图,就像用于回归的内置图函数一样。我该如何编写自己的代码?

Jav*_*Jav 5

您可以使用menu()from utilsswitch


keep_loop = TRUE
while (keep_loop) {
  switch (menu(c("cars", "iris", "exit"), title = "Which dataset to plot?"),
          1 == {
            plot(cars)
            lines(lowess(cars))
          },
          2 == {
            plot(iris[, 1:2])
            lines(lowess(iris[, 1:2]))
          },
          3 == {
            keep_loop = FALSE
          })
}
Run Code Online (Sandbox Code Playgroud)

如果您只是想要提示而没有选择图(或返回图)的能力,请使用 readline()

plot(cars)
invisible(readline(prompt="Press [enter] to continue"))
lines(lowess(cars))
Run Code Online (Sandbox Code Playgroud)