[R] trouble with combining png and pdf

Yihui Xie xieyihui at gmail.com
Thu Oct 16 06:36:19 CEST 2008


I'd like to suggest you "combine" them in R instead of using other
software. For example, you can use low-level plot commands to add the
points to the image plot.

If you insist on combining them together, you may use the utility
"composite" in ImageMagick, but I don't recommend you to combine a pdf
file to a png file, as the output pdf will be ugly and the file size
is still big. Combining png files to another png image will be much
better.

## note the transparent background!
png(file = "x.png", width = 600, height = 600, bg = "transparent")
image(matrix(runif(10000), 100))
dev.off()
png(file = "y.png", width = 600, height = 600, bg = "transparent")
plot(1:100)
dev.off()
##

Then go to the command window or other terminals, use "composite y.png
x.png z.png"

You can also use Adobe Acrobat Professional or other software to
optimize the file size of your pdf output. These issues are irrelevant
to R, so I'll not provide further details here.

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086
Mobile: +86-15810805877
Homepage: http://www.yihui.name
School of Statistics, Room 1037, Mingde Main Building,
Renmin University of China, Beijing, 100872, China



On Wed, Oct 15, 2008 at 8:51 PM, Sander Botter <s.botter at erasmusmc.nl> wrote:
> L.S.,
>
>
>
> I would like to add a downsized image to a pdf file and got stuck on the
> code to use.
>
> My goal is to open a pdf device, add a plot, add the downsized image, and
> then close the pdf device.
>
>
>
> Making the downsized image is easy using png(),
>
>
>
> png(file="x.png", width = 600, height = 600, units="px", pointsize=12)
>
> image(very large image)
>
> dev.off()
>
>
>
> making a pdf with a plot as well using pdf(),
>
>
>
> pdf(file = "y.pdf", paper="letter", width=8.5, height=11)
>
> plot(1:100)
>
> dev.off()
>
>
>
> However this produces two separate files and my goal is to export the
> downsized image (as png) into the pdf file (behind the plot)!
>
> Maybe anyone has some suggestions?
>
>
>
> Regards,
>
>
>
> Sander Botter
>
> Erasmus Medical Centre, Rotterdam, The Netherlands
>



More information about the R-help mailing list