[R] dev.print and X11(canvas = "black")

Jeffrey J. Hallman m1jjh00 at frb.gov
Tue Mar 2 16:17:39 CET 2004


Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:

   > On Mon, 1 Mar 2004 jhallman at frb.gov wrote:

  >> In Splus, I often use graphics windows with a black background and white
  >> foreground.  The S print.graph() function sends the current plot to my
  >> printer but with a white background and black foreground.  I'd like to

   > S (and S-PLUS) only has a few colour numbers, and you can change their 
   > interpretation on the screen graphics devices after plotting.  R does plot 
   > in colours rather than numbers.

  >> be able to do something similar in R, but can't figure out how.  I've
  >> tried various permutations of dev.copy() and dev.print(), but it seems
  >> that the foreground color is fixed when the original plot is drawn, and
  >> dev.copy always redraws it with that color.  So even though I can get my
  >> postscript output with a white background, things that were drawn white on the
  >> dark background of my X11 device are still drawn white when dev.copy'd
  >> to a postscript device.  Since the postscript has a white background,
  >> that means the white foreground stuff doesn't show up.
  >> 
  >> Is there a way to handle this?  Or do I just have to give up on ever
  >> using a dark canvas in X11() if I ever want to print the result?

   > There are many ways to print the result, and re-running the plot commands 
   > after switching to a postscript() device is one of the best.  This would 
   > work for you if you only ever use colour numbers and switch the palette
   > (and par("fg")).

Jim Lemon made essentially the same suggestion: run the code that
created the plot twice, once with X11 as the active device, and again
with postscript as the active device.

The trouble with this is that is doesn't handle plots that the user has
edited.  I have some charts that users add things to interactively,
using combinations of locator(), text(), mtext(), and arrows().  There's
no nice way to know what a user has done to a plot before he attempts to
print it.

I know that R is internally maintaining a display list.  Is there a way
to access that without dropping into C?  And what's in it, anyway?

Jeff




More information about the R-help mailing list