From baptiste.auguie at googlemail.com  Thu Sep  9 08:48:39 2010
From: baptiste.auguie at googlemail.com (baptiste auguie)
Date: Thu, 9 Sep 2010 08:48:39 +0200
Subject: [Rd] [R] large files produced from image plots?
In-Reply-To: <4C87F51F.90207@auckland.ac.nz>
References: <SNT131-w28F3D126917CB8C87B2DAABB720@phx.gbl>
	<2277A910-3029-4080-BF1E-BBD4F3C1CC6E@gmail.com>
	<SNT131-w112E008F02638748589BD9BB720@phx.gbl>
	<AANLkTinNQKhxcDvrMa23-FYmfUR_m-u8WDi4_zh2KQ68@mail.gmail.com>
	<4C87F51F.90207@auckland.ac.nz>
Message-ID: <AANLkTinvY2Y4Cyg-SC42mq7gg9Ehe86hqqc4wbuDuNbd@mail.gmail.com>

Hi,

Oops, I probably spoke too quickly about the pdf() output. I attach
the quartz() result, the pdf() result, and a screenshot of what I saw
using the built-in Preview program of MacOS... Here the pdf appeared
to be wrong, with a strange interpolation going on. I opened the same
file in Acrobat and it's fine, so I guess it's a bug in the pdf
viewer, as is often the case with pdf artifacts.

My code:


pdf("test-raster.pdf")
image <- as.raster(matrix(0:1, ncol=5, nrow=3)); plot.new()
rasterImage(image, 0, 0, 1, 1, interpolate=FALSE)
dev.off()

Best,

baptiste


On 8 September 2010 22:42, Paul Murrell <p.murrell at auckland.ac.nz> wrote:
> Hi
>
> [shifted this to r-devel]
>
> I can't reproduce this yet on my systems, but I have heard of at least one
> other example of a raster-related crash (on a 64-bit system I think).
>
> Baptiste: I would love to see that broken PDF if you still have it.
>
> Paul
>
> On 9/09/2010 8:00 a.m., baptiste auguie wrote:
>>
>> Hi,
>>
>> I get the same crash with x11() with sessionInfo()
>> R version 2.11.1 (2010-05-31)
>> x86_64-apple-darwin9.8.0
>>
>> locale:
>> [1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8
>>
>> attached base packages:
>> [1] grid ? ? ?stats ? ? graphics ?grDevices utils ? ? datasets ?methods
>> [8] base
>>
>> However it works fine with quartz(). Have you tried other devices?
>> pdf() doesn't crash R for me, but the output is incorrect. png() is OK
>> but defeats the purpose here.
>>
>> rasterImage is quite a recent addition, it would probably be
>> appreciated to report any such odd behavior to R-devel. Interestingly
>> (or not), the x11() test does not crash for me using grid.raster
>> instead of rasterImage.
>>
>> Best,
>>
>> baptiste
>>
>>
>>
>>
>>
>>
>>
>> On 8 September 2010 21:47, Stephen T.<obsessively at hotmail.com> ?wrote:
>>>
>>> Hi Baptiste,
>>> Thanks for your suggestion. I have to look into this further, but
>>> anything I
>>> try with rasterImage() gives me this type of error (below is from running
>>> the example in the help file). This is with R 2.11.1 on OS X 10.5 -
>>> ?*** caught bus error ***
>>> address 0x24, cause 'non-existent physical address'
>>> Traceback:
>>> ?1: rasterImage(image, 100, 300, 150, 350, interpolate = FALSE)
>>> Possible actions:
>>> 1: abort (with core dump, if enabled)
>>> 2: normal R exit
>>> 3: exit R without saving workspace
>>> 4: exit R saving workspace
>>> This is not an obvious error, is it?
>>> Thanks,
>>> Stephen
>>>>
>>>> Subject: Re: [R] large files produced from image plots?
>>>> From: baptiste.auguie at googlemail.com
>>>> Date: Wed, 8 Sep 2010 19:41:46 +0200
>>>> CC: r-help at r-project.org
>>>> To: obsessively at hotmail.com
>>>>
>>>> Hi,
>>>>
>>>> Have you tried the recent rasterImage() function?
>>>>
>>>> HTH,
>>>>
>>>> baptiste
>>>>
>>>> On Sep 8, 2010, at 7:30 PM, Stephen T. wrote:
>>>>
>>>>>
>>>>> Hi list,
>>>>> I wonder if anyone has thoughts on making image plots in R [using
>>>>> image() or image.plot(), or filled.contour()]- I've made quite a bit
>>>>> now,
>>>>> but they seem quite large in size when exported to pdf file format
>>>>> (even
>>>>> after compressing with pdftk or ghostscript, which I regularly do). I
>>>>> know
>>>>> that for "images", raster graphics output (png, tiff) may be the way to
>>>>> go,
>>>>> but often the ones I make are multi-panel plots with other graphics on
>>>>> them,
>>>>> and are usually included in a LaTeX document (PDFLaTeX does accept png)
>>>>> and
>>>>> require stretching/shrinking (and/or possibly editing with Adobe
>>>>> Illustrator). I have had some luck exporting image plots from Matlab
>>>>> (to
>>>>> postscript or pdf) before in the sense that the files seem smaller and
>>>>> less
>>>>> pixelated. Is this a difference in the way image() plots are produced,
>>>>> or
>>>>> with the way the image is written to the pdf() device (if anyone is
>>>>> familiar
>>>>> with other image-exporting programs...)? The other day I had a 13MB
>>>>> dataset,
>>>>> and probably plotted 3/4 of it!
>>>>> using image() and the compressed pdf output was about 8 MB (it
>>>>> contained
>>>>> other stuff but was an addition of a few KB). I tried filled.contour(),
>>>>> as I
>>>>> understand that it colors polygons to fill contours instead of coloring
>>>>> rectangles at each pixel - and it has saved me before - but this time
>>>>> the
>>>>> contours may have been too sharp as as its compressed pdf came out to
>>>>> be 62
>>>>> MB... (ouch!). I have not tested this data set with other software
>>>>> programs
>>>>> so it may just have been a difficult data set.
>>>>> Is there a good solution to this (or is it simply not to use a
>>>>> vector-graphics format in these instances), and just for my curiosity,
>>>>> are
>>>>> you aware of any things that other software (data analysis) programs do
>>>>> uder
>>>>> the hood to make their exported images smaller/smoother?
>>>>> Thanks much!
>>>>> Stephen
>>>>> [[alternative HTML version deleted]]
>>>>>
>>>>> ______________________________________________
>>>>> R-help at r-project.org mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>>> PLEASE do read the posting guide
>>>>> http://www.R-project.org/posting-guide.html
>>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>
>>>
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> --
> Dr Paul Murrell
> Department of Statistics
> The University of Auckland
> Private Bag 92019
> Auckland
> New Zealand
> 64 9 3737599 x85392
> paul at stat.auckland.ac.nz
> http://www.stat.auckland.ac.nz/~paul/
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pdf-raster.pdf
Type: application/pdf
Size: 2266 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20100909/a631a286/attachment.pdf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: quartz-raster.pdf
Type: application/pdf
Size: 5544 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20100909/a631a286/attachment-0001.pdf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: screenshot-pdf-Preview.png
Type: image/png
Size: 72584 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20100909/a631a286/attachment.png>


[Rd] [R] large files produced from image plots?
baptiste auguie