【发布时间】:2019-08-07 22:24:30
【问题描述】:
我想在 R 中绘制多个图形。但是,我不想使用 par() 或 layout() 函数。我想通过按回车键来更改绘图,就像用于回归的内置绘图功能一样。我怎样才能为此编写自己的代码?
【问题讨论】:
标签: r plot regression
我想在 R 中绘制多个图形。但是,我不想使用 par() 或 layout() 函数。我想通过按回车键来更改绘图,就像用于回归的内置绘图功能一样。我怎样才能为此编写自己的代码?
【问题讨论】:
标签: r plot regression
您可以从utils 和switch 使用menu():
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))
【讨论】: