[R] overlapping a plot with an external image

Jim Lemon bitwrit at ozemail.com.au
Thu May 22 12:54:26 CEST 2003


Meinhard Ploner wrote:
> It's possible to overlap an external image (jpg or pdf)
> with a plot generated with R?
>
> Specifying the image as the background
> of the plot might not be possible...
>
If the plot is output using postscript(), the default background color is 
transparent. For instance, if you have a plot produced 
with postscript(...,onefile=FALSE,...) named Rplots.ps, you can insert the 
following lines in another Postscript file to get the plot overlaid on 
whatever image is in that file.

...
%%DocumentNeededFiles: /home/jim/analyses/Rplots.ps
...
gsave
x y translate
x y scale
(/home/jim/R/analyses/Rplots.ps) run
grestore
...

the "translate" and "scale" commands allow you to place the plot where you 
want it and get the correct size. It's not too hard, but it helps if you 
have had some experience with Postscript. Once you have gotten the 
translate and scale factors right (Ghostview is a great help) you can just 
keep plugging your plots in unless you want to change the image size.

Jim




More information about the R-help mailing list