Hello Lasse,

Why not try this?

(1) Create 20MB PDF from R
(2) use convert command in linux, examples below:

convert -resize 50% <20mbfile.pdf> <smallerfile.pdf>
convert -resize 75% <20mbfile.pdf> <image.png>

Ghostscript can help you as well for conversion! Using vector formats
(pdf,ps,eps) are good for this purpose, as opposed to scalar (png, jpg,
etc.).

Best,
Parthiban.


2009/10/23 Jim Lemon <j...@bitwrit.com.au>

> On 10/23/2009 06:07 AM, Lasse Kliemann wrote:
>
>> I wish to save a scatter plot comprising approx. 2 million points
>> in order to include it in a LaTeX document.
>>
>> Using 'pdf(...)' produces a file of size about 20 MB, which is
>> useless.
>>
>> Using 'cairo_pdf(...)' produces a smaller file, around 3 MB. This
>> is still too large. Not only that the document will be too large,
>> but also PDF viewers choke on this. Moreover, Cairo has problems
>> with text: by default text looks ugly, like scaled bitmaps. After
>> hours of trying different settings, I discovered that choosing a
>> different font family can help, e.g.: 'par(family="Mono")'. This
>> gives good-looking text. Yet, the problem with the file size
>> remains.
>>
>> There exists the hint to produdc EPS instead and then convert to
>> PDF using 'epstopdf'. The resulting PDF files are slightly
>> smaller, but still too large, and PDF viewers still don't like
>> it.
>>
>> So I gave PNG a try. PNG files are much smaller and PDF viewers
>> have no trouble with them. However, fonts look ugly. The same
>> trick that worked for Cairo PDF has no effect for PNG. When I
>> view the PNGs with a dedicated viewer like 'qiv', even the fonts
>> look good. But not when included in LaTeX; I simply use
>> '\includegraphics{...}' and run the document through 'pdflatex'.
>>
>> I tried both, creating PNG with 'png(...)' and converting from
>> PDF to PNG using 'convert' from ImageMagick.
>>
>> So my questions are:
>>
>> - Is there a way to produce sufficiently lean PDFs directly in R,
>>   even when the plot comprises several million points?
>>
>> - How to produce a PNG that still looks nice when included in a
>>   LaTeX PDF document?
>>
>> Any hints will be greatly appreciated.
>>
>>
> Hi Lasse,
> I may be right off the track, but I can't make much sense of 2 million
> points in a scatterplot. If you are interested in the density of points
> within the plot, you could compute this using something like the bkde2
> function in the KernSmooth package and then plot that using something like
> "image".
>
> Jim
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to