[R-SIG-Mac] Fighting with lattice output to files

Ben Haller rsigmac at sticksoftware.com
Mon Mar 21 18:01:16 CET 2011


  Hi all.  I'm trying to use lattice to make some plots with wireframe().  Ultimately I want to output these plots to PDF files, but I can't get that to work.  I'm battling a number of issues.  Note the problem is not the lack of a print() call, I'm aware of that issue.  :->  I'm posting here because I imagine that the graphics device issues I am seeing are platform-specific.

1. Using device "jpeg" uses awful-looking results, apparently rendered with X11.  This is a bit odd, as when I was last doing this sort of thing, I seem to recall very similar code (which I copied and pasted from where it was) producing nice-looking images that were not rendered with X11.  Did the implementation of the jpeg device on Mac change?

2. Using the device "quartz" (not to file, just trying to use it to go to screen) produces errors:

Mon Mar 21 12:41:40 darwin.local R[25609] <Error>: kCGErrorRangeCheck: CGSNewWindowWithOpaqueShape: Cannot create window
Mon Mar 21 12:41:40 darwin.local R[25609] <Error>: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.

  This happens quite reproducibly (just do "trellis.device(device="quartz", width=640, height=640)" in the R console, in fact).  I don't know whether lattice is supposed to be compatible with the quartz device or not, but it certainly doesn't seem to be.  And this error hoses R so thoroughly that you have to quit and restart it, as far as I can tell, which makes it a bit annoying; don't say I didn't warn you :->.

3. Using the device "pdf" produces pdf files that have the correct graphics, but have no text (axis labels, tick labels).  This is true whether I try to explicitly specify the font (fontfamily="Times" or fontfamily="HersheySans") or do not specify any font.

4. Using no device at all (i.e. no call to trellis.device, just printing my wireframe object) gives me lovely-looking output, but in a window, of course, not a file.  This is a bit of a head-scratcher since trying to use device "quartz" produces errors; what device is lattice using, then, if not quartz?  Anyhow, trying to pass file settings (device and filename) to wireframe() in par.settings seems to get ignored, as far as I can tell, so I can't build on this success to generate the files I want.

  I've been googling and reading for an hour now, and can't seem to find any info on this, nor any sample code showing how to get trellis output to a pdf file (not any sample code that looks substantially different from the approach I'm taking, that is).  So I'm rather at my wits end.  Anybody?  Can someone please post working sample code for trellis output to PDF that works on the current Mac build of R, at a minimum, and then maybe I can figure this out for myself?

  My full code is too hairy to post here, I think, but the nutshell is:

plotFishyWireframe <- function(...)
{
	...stuff...
	wf_obj <- wireframe(t(zValues), xlab=xlab, ylab=ylab, zlab=zlab, scales=scales, zlim=zlim, main=list(label=plotTitle, cex=1.5), drape=TRUE, at=zcuts, col.regions=zcolors, colorkey=TRUE, screen=screen, perspective=perspective, par.settings=theme)
	print(wf_obj)
}

...stuff...

trellis.device(device="pdf", file="foo.pdf", width=640, height=640)
plotFishyWireframe(...)
dev.off()

  Thanks in advance!

Ben Haller
McGill University



More information about the R-SIG-Mac mailing list