首页 文章

如何在R中从点到线更改默认绘图类型?

提问于
浏览
5

我正在与数百万积分的时间序列合作 . 我通常用这个数据绘制

plot(x,type='l')

如果我不小心打字,事情会变得非常缓慢

plot(x)

因为默认是 type='p'

在R会话期间有没有办法使用 setHook() 或其他东西修改默认 plot(type=...)

我从How to set a color by default in R for all plot.default, plot or lines calls看到这可以为 par() 参数完成,如'col' . 但 par() 中似乎没有任何点对线设置 .

1 回答

  • 7

    一个轻量级的解决方案就是定义一个包装函数,该函数使用 type="l" 调用 plot() 以及您默认的任何其他参数,其中一些是mentioned here

    lplot <- function(...) plot(..., type="l")
    
    x <- rnorm(9)
    par(mfcol=c(1,2))
    plot(x, col="red", main="plot(x)")
    lplot(x, col="red", main="lplot(x)")
    

    enter image description here

相关问题