rdefaults

How to change R plot default options


I'd like to change default plot option from type = "p" to type = "l" ; I mean I want it is like that at the beginning of each new session, without specifying it any more.

I've tried to put some piece of code in my Rprofile.site but unfortunately not the right one: firstly I wanted to use setDefaults but this package is deprecated; I also tried to set a hook but couldn't make it work.

Any ideas ?

thanks !


Solution

  • This could be done by adding to your Rprofile

    formals(plot.default)$type <- "l"
    

    But that would be highly discouraged, for the reasons Roland states in his comment. A better solution would be to place this in your Rprofile:

    lplot <- function(x, y, type = "l", ...){
        plot(x, y, type = type, ...)
    }
    

    This gives you the default you want, the ability to revert back to normal if wanted, and doesn't affect the existing plot function.

    But this still comes with the downside of the lplot function seemingly appearing out of nowhere. Far better would be to put lplot in a package. Even if you load the package in the Rprofile, at least ?lplot will pull up something to indicate where it came from.