[R-SIG-Mac] Fighting with lattice output to files
David Winsemius
dwinsemius at comcast.net
Mon Mar 21 21:33:55 CET 2011
On Mar 21, 2011, at 4:13 PM, Ben Haller wrote:
> Oh! I thought trellis.device always took a size in pixels;
> certainly it does for the jpeg type! I guess it is device-dependent?
Well, yes (to it's device dependent). No need to guess. From help(pdf)
width, height
the width and height of the graphics region in inches. The default
values are 7.
> OK, I will go try that. :->
>
> Thanks!
>
> Ben Haller
> McGill University
>
>
> On Mar 21, 2011, at 1:39 PM, Yan Zhou wrote:
>
>> I suspect the problem with the PDF device is that as in Ben's code,
>> a 640 by 640 inches PDF is produced, and the default size of fonts
>> is 12 points, so they are too small to be seen.
>>
>> On Mar 21, 2011, at 5:24 PM, Simon Urbanek <simon.urbanek at r-project.org
>> > wrote:
>>
>>> Ben,
>>>
>>> On Mar 21, 2011, at 1:01 PM, Ben Haller wrote:
>>>
>>>> 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?
>>>>
>>>
>>> jpeg() does what you tell it to - see the type argument to pick
>>> the appropriate back-end.
>>>
>>>
>>>> 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).
>>>
>>> Well, you're asking for a device size of 17.8 yards x 17.8 yards
>>> (width/height is in inches!) - I want to see the screen that can
>>> handle that ;). But, it should not crash, admittedly, so I'll add
>>> a check to avoid crash on such user errors.
>>>
>>>
>>>> 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.
>>>>
>>>
>>> I cannot reproduce that - taking the wireframe example from
>>> trellis the text appears perfectly normal (pdf() device and
>>> Preview to display it).
>>>
>>> If in doubt, see ?pdf and ?pdfFonts for dealing with fonts and the
>>> pdf() device -- the fontfamily is not necessarily what matters here.
>>>
>>>
>>>> 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?
>>>
>>> It does use Quartz but with reasonable sizes ;). In the R.app GUI
>>> uou can use quartz.save() to save the output of that window
>>> WYSIWYG to almost any file format.
>>>
>>> Cheers,
>>> Simon
>>>
>>>
>>>
>>>> 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
>>>>
>>>> _______________________________________________
>>>> R-SIG-Mac mailing list
>>>> R-SIG-Mac at r-project.org
>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>>>>
>>>>
>>>
>>> _______________________________________________
>>> R-SIG-Mac mailing list
>>> R-SIG-Mac at r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>>
>
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-SIG-Mac
mailing list