The issue is how to include external graphical images in R plots?
There are two main sorts of graphics formats to consider: bitmaps (e.g., PNG, JPEG) and vector graphics (e.g., PostScript, PDF).
Importing bitmaps
The pixmap
package facilitates drawing bitmaps
as part of R plots. This package works with an R structure
called a pixmap
and there are functions for reading
external files in one of the pnm
(portable anymap) formats
to create a pixmap
. There are external applications for
converting other bitmap formats to pnm
.
In summary, you can take a bitmap file in any format, convert it to
one of the
pnm
formats (e.g., using ImageMagick's convert
)
and then read that into R and draw it using pixmap
.
Importing vector graphics
UPDATE: there is now a package grImport
on CRAN
for importing vector graphics into R.
Nothing exists for this yet (though see experiments below).
There are three important issues:
So far I have experimented a bit with PostScript as the target format, using GhostScript to convert PostScript to a custom plain text format, and reading the plain text format into generic R objects. The results of this experimentation are described here.
Importing bitmaps as vector graphics
This is harder still, but there are a couple of possibilities to consider:
autotrace
. I personally haven't had a lot of success
with trying this out.
locator()
or
grid.locator()
to "trace" it. Only makes sense
for quite simple shapes (i.e., only with a few vertices to trace).
I have experimented a little with the second option, as described here.