【问题标题】:How to change code for plot function of a regression?如何更改回归绘图函数的代码?
【发布时间】:2019-08-07 22:24:30
【问题描述】:

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

【问题讨论】:

    标签: r plot regression


    【解决方案1】:

    您可以从utilsswitch 使用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))
    

    【讨论】:

    • 我不知道这可以这么容易,我的恭维。
    猜你喜欢
    • 1970-01-01
    • 2013-09-17
    • 1970-01-01
    • 2021-10-10
    • 1970-01-01
    • 2018-12-29
    • 2019-03-01
    • 2015-03-14
    相关资源
    最近更新 更多