6

I am working with timeseries with millions of points. I normally plot this data with

plot(x,type='l')

Things slow down terribly if I accidentally type

plot(x)

because the default is type='p'

Is there any way using setHook() or something else to modify the default plot(type=...) during an R session?

I see from How to set a color by default in R for all plot.default, plot or lines calls that this can be done for par() parameters like 'col'. But there doesn't appear to be any points-vs-line setting in par().

Community
  • 1
  • 1
  • 1
    You might find the [defaults](http://cran.r-project.org/web/packages/Defaults/) package useful? – joran May 31 '13 at 18:54

1 Answers1

7

A lightweight solution is to just define a wrapper function that calls plot() with type="l" and any other arguments you've given it. This approach has some possible advantages over changing an existing function's defaults, a few of them 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

Community
  • 1
  • 1
Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455
  • 1
    As long as there is no equivalent to par(plot.type='l'), this looks like the simplest and safest solution. – Jonathan Callahan Jun 01 '13 at 00:48
  • @JonathanCallahan -- Yeah, there's nothing in the `par` list that will let you set the plot type. In **lattice** graphics, you could prob. do the equivalent by changing the default for `panel.xyplot`, but that'd not be much better than using the **Defaults** library. – Josh O'Brien Jun 01 '13 at 00:52