Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change default plot type from points to line in R?

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().

like image 666
Jonathan Callahan Avatar asked May 31 '13 18:05

Jonathan Callahan


1 Answers

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

like image 192
Josh O'Brien Avatar answered Nov 02 '22 23:11

Josh O'Brien