如何更改回归的绘图函数的代码?

问题描述 投票:-1回答:1

我想在R中绘制多个图形。但是,我不想使用par()或layout()函数。我想通过按回车来改变图,就像回归的内置绘图函数一样。我怎么能为此编写自己的代码?

r plot regression
1个回答
5
投票

你可以使用menu()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
          })
}

如果您只是想要一个无法选择绘图(或返回)的提示,请使用readline()

plot(cars)
invisible(readline(prompt="Press [enter] to continue"))
lines(lowess(cars))
© www.soinside.com 2019 - 2024. All rights reserved.