[R] Followup: copy-paste graphics from R to Word on Mac OS X
sfalcon at fhcrc.org
Fri Mar 7 00:18:41 CET 2003
I've encountered some of the same issues with jaggy graphics. Here
is what I have found to work pretty well:
Short and sweet:
Use the bitmap() function with res=200 to create png files.
As far as I can tell, png(), jpg(), and friends do not allow you to
set the resolution. However, you can set the resolution using
bitmap(). I've had good results with res=200.
The tricky part about using bitmap() is that it relies on having
GhostScript installed and may require you to set an environment
variable (Will this have any chance of working on a Mac?)
On my Windows 2000 system, I have
R_GSCMD = c:\gs\gs8.00\bin\gswin32c.exe
I can then create a png image that looks decent like this:
fname <- "sineWave.png"
x <- seq(0,6.5, .1)
y <- sin(x)
bitmap(file=fname, type="png256", width=4, height=4, res=200)
If you want to automate plot creation, you may need to utilize the
Sys.sleep() function. If you call a script like this:
rterm --slave --no-save --no-restore < autoPNGplot.r
then R may complete before GhostScript gets a chance to start and
GhostScript will crash because it can't find the files it was told
to process. Sleeping for a few seconds seems to take care of this.
You can test this yourself by trying to run the above sine wave
script redirected into rterm. For me it crashes unless I add
Sys.sleep(2) at the end.
Hope these notes are somewhat helpful.
More information about the R-help