thomas.friedrichsmeier at ruhr-uni-bochum.de
2007-Mar-06 14:03 UTC
[Rd] Wish: Option to configure the default par() (PR#9545)
Full_Name: Thomas Friedrichsmeier Version: 2.4.1 OS: linux (Debian unstable) Submission from: (NULL) (84.60.113.185) Summary: It would be nice to have a centralized option for setting default par() options for all devices and all plots. This would ease producing graphs in a customized but consistent way. Suggesting options("par.default"). Example problem: Make all graphs look like par(bg="light gray", las=2) both on screen and for various produced file formats such as png() and postscript(). Current situation: To solve the example problem, two approaches come to mind: 1) Always call par() before the next plot. This could be wrapped into a function to make it easier to stay consistent. E.g.: postscript() myDefaultPar() # calls par(bg="light gray", las=2) plot(...) 2) Create wrappers for all devices of interest, like e.g. (not quite correct, but good enough for this example): myX11 <- function(...) { X11(...) par(bg="light gray", las=2) } Both solutions work, but are not entirely elegant. The drawback of 1) is that you still need to add the given line manually at all places. The drawback of 2) is that a similar wrapper will have to be created (and used) for each different device. Wish: Add a new option: options("par.default"), similar to the existing options("par.ask.default"). This option would accept a list of all par settings to set a custom default for: options(par.default=list(bg="light gray", las=2)) par() options specified while creating the device, in calls to plot() or in subsequent calls to par() would take precendence over options("par.default").
Greg Snow
2007-Mar-06 16:56 UTC
[Rd] Wish: Option to configure the default par() (PR#9545)
Another approach may be to use hooks (see ?setHook). The plot.new function already has a hook, so you could do your option #1 automatically by setting that hook. Better would be if all the graphics device functions had hooks (or a common hook), then you could set that hook to set your graphics parameters and they would be set every time a new graphics device was started. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111> -----Original Message----- > From: r-devel-bounces at r-project.org > [mailto:r-devel-bounces at r-project.org] On Behalf Of > thomas.friedrichsmeier at ruhr-uni-bochum.de > Sent: Tuesday, March 06, 2007 7:04 AM > To: r-devel at stat.math.ethz.ch > Cc: R-bugs at biostat.ku.dk > Subject: [Rd] Wish: Option to configure the default par() (PR#9545) > > Full_Name: Thomas Friedrichsmeier > Version: 2.4.1 > OS: linux (Debian unstable) > Submission from: (NULL) (84.60.113.185) > > > Summary: It would be nice to have a centralized option for > setting default par() options for all devices and all plots. > This would ease producing graphs in a customized but > consistent way. Suggesting options("par.default"). > > Example problem: Make all graphs look like > > par(bg="light gray", las=2) > > both on screen and for various produced file formats such as > png() and postscript(). > > Current situation: To solve the example problem, two > approaches come to mind: > 1) Always call par() before the next plot. This could be > wrapped into a function to make it easier to stay consistent. E.g.: > > postscript() > myDefaultPar() # calls par(bg="light gray", las=2) > plot(...) > > 2) Create wrappers for all devices of interest, like e.g. > (not quite correct, but good enough for this example): > > myX11 <- function(...) { > X11(...) > par(bg="light gray", las=2) > } > > Both solutions work, but are not entirely elegant. The > drawback of 1) is that you still need to add the given line > manually at all places. The drawback of 2) is that a similar > wrapper will have to be created (and used) for each different device. > > Wish: > Add a new option: options("par.default"), similar to the > existing options("par.ask.default"). This option would accept > a list of all par settings to set a custom default for: > > options(par.default=list(bg="light gray", las=2)) > > par() options specified while creating the device, in calls > to plot() or in subsequent calls to par() would take > precendence over options("par.default"). > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
Greg.Snow at intermountainmail.org
2007-Mar-06 16:56 UTC
[Rd] Wish: Option to configure the default par() (PR#9545)
Another approach may be to use hooks (see ?setHook). The plot.new function already has a hook, so you could do your option #1 automatically by setting that hook. Better would be if all the graphics device functions had hooks (or a common hook), then you could set that hook to set your graphics parameters and they would be set every time a new graphics device was started. --=20 Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111 =20 =20> -----Original Message----- > From: r-devel-bounces at r-project.org=20 > [mailto:r-devel-bounces at r-project.org] On Behalf Of=20 > thomas.friedrichsmeier at ruhr-uni-bochum.de > Sent: Tuesday, March 06, 2007 7:04 AM > To: r-devel at stat.math.ethz.ch > Cc: R-bugs at biostat.ku.dk > Subject: [Rd] Wish: Option to configure the default par() (PR#9545) >=20 > Full_Name: Thomas Friedrichsmeier > Version: 2.4.1 > OS: linux (Debian unstable) > Submission from: (NULL) (84.60.113.185) >=20 >=20 > Summary: It would be nice to have a centralized option for=20 > setting default par() options for all devices and all plots.=20 > This would ease producing graphs in a customized but=20 > consistent way. Suggesting options("par.default"). >=20 > Example problem: Make all graphs look like >=20 > par(bg=3D"light gray", las=3D2) >=20 > both on screen and for various produced file formats such as=20 > png() and postscript(). >=20 > Current situation: To solve the example problem, two=20 > approaches come to mind: > 1) Always call par() before the next plot. This could be=20 > wrapped into a function to make it easier to stay consistent. E.g.: >=20 > postscript() > myDefaultPar() # calls par(bg=3D"light gray", las=3D2) > plot(...) >=20 > 2) Create wrappers for all devices of interest, like e.g.=20 > (not quite correct, but good enough for this example): >=20 > myX11 <- function(...) { > X11(...) > par(bg=3D"light gray", las=3D2) > } >=20 > Both solutions work, but are not entirely elegant. The=20 > drawback of 1) is that you still need to add the given line=20 > manually at all places. The drawback of 2) is that a similar=20 > wrapper will have to be created (and used) for each different device. >=20 > Wish: > Add a new option: options("par.default"), similar to the=20 > existing options("par.ask.default"). This option would accept=20 > a list of all par settings to set a custom default for: >=20 > options(par.default=3Dlist(bg=3D"light gray", las=3D2)) >=20 > par() options specified while creating the device, in calls=20 > to plot() or in subsequent calls to par() would take=20 > precendence over options("par.default"). >=20 > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >=20
thomas.friedrichsmeier at ruhr-uni-bochum.de
2007-Mar-07 15:05 UTC
[Rd] Wish: Option to configure the default par() (PR#9545)
--nextPart4163908.Y9KBlY7Qjy Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Tuesday 06 March 2007 17:56, Greg Snow wrote:> Another approach may be to use hooks (see ?setHook). The plot.new > function already has a hook, so you could do your option #1 > automatically by setting that hook. > > Better would be if all the graphics device functions had hooks (or a > common hook), then you could set that hook to set your graphics > parameters and they would be set every time a new graphics device was > started.Thanks for your suggestion. This does almost everything I want. Two small=20 drawbacks: 1) Setting par(bg=3D...) from the hook has no effect for the first graph plotted=20 in the new device. For this to work, the hook would need to be called=20 before .Internal(plot.new()) instead of afterwards in plot.new(). 2) Any par() parameters explicitely set in the call to X11()/postscript()..=2E=20 will be overridded, instead of taking precendence over the defaults. =46or many purposes this method is really useful, however, so thanks again for=20 pointing it out. Regards Thomas --nextPart4163908.Y9KBlY7Qjy Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQBF7tTmEKRv+5DVNhgRAhZ4AJ9StffA3KSO+h4ONdkWE7A1JarXWACdF8vu pRW+6rL5DCS8iXppfxdIk88=rKvB -----END PGP SIGNATURE----- --nextPart4163908.Y9KBlY7Qjy--
Gabor Grothendieck
2007-Mar-07 17:04 UTC
[Rd] Wish: Option to configure the default par() (PR#9545)
Here are a few ideas: For #1 define: "$.Par" <- function(x, FUN) { par.default <- getOption("par.default") if (!is.null(par.default)) do.call("par", par.default) get(FUN, parent.frame()) } Par <- structure(NA, class = "Par") # and now one can preface any function with Par$ and it will # call par and then the function. This eliminates an extra statement # but does mean you have to preface plot, say, with Par$ # e.g. options(par.default = list(bg = "light gray", las = 2)) Par$plot(1:10) Par$boxplot(1:10) For #2 do: plot <- Par$plot Another idea for #2 is to use the connect package. See: http://code.google.com/p/r-connect/ On 3/6/07, thomas.friedrichsmeier at ruhr-uni-bochum.de <thomas.friedrichsmeier at ruhr-uni-bochum.de> wrote:> Full_Name: Thomas Friedrichsmeier > Version: 2.4.1 > OS: linux (Debian unstable) > Submission from: (NULL) (84.60.113.185) > > > Summary: It would be nice to have a centralized option for setting default par() > options for all devices and all plots. This would ease producing graphs in a > customized but consistent way. Suggesting options("par.default"). > > Example problem: Make all graphs look like > > par(bg="light gray", las=2) > > both on screen and for various produced file formats such as png() and > postscript(). > > Current situation: To solve the example problem, two approaches come to mind: > 1) Always call par() before the next plot. This could be wrapped into a function > to make it easier to stay consistent. E.g.: > > postscript() > myDefaultPar() # calls par(bg="light gray", las=2) > plot(...) > > 2) Create wrappers for all devices of interest, like e.g. (not quite correct, > but good enough for this example): > > myX11 <- function(...) { > X11(...) > par(bg="light gray", las=2) > } > > Both solutions work, but are not entirely elegant. The drawback of 1) is that > you still need to add the given line manually at all places. The drawback of 2) > is that a similar wrapper will have to be created (and used) for each different > device. > > Wish: > Add a new option: options("par.default"), similar to the existing > options("par.ask.default"). This option would accept a list of all par settings > to set a custom default for: > > options(par.default=list(bg="light gray", las=2)) > > par() options specified while creating the device, in calls to plot() or in > subsequent calls to par() would take precendence over options("par.default"). > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >