R: Convert a filename into a complete LaTeX 'includegraphics'...
as.includegraphics
R Documentation
Convert a filename into a complete LaTeX includegraphics command.
This is useful for pdf, png, and jpeg files that are recognized by
the LaTeX includegraphics macro in the graphicx package
when used with the pdflatex command.
This is useful for bmp and tiff files that are recognized by
the LaTeX includegraphics macro in the graphicx package
when used with the latex command.
Description
Convert a filename into a complete LaTeX includegraphics command.
The directory name is included in the command. The includegraphics
macro is generated with the height and optional width. An optional
raise value is available for vertical alignment. An optional trim
argument is available to remove excess margins from the image. See the
Details section for use of the trim argument to take panels out
of an externally produced graphics file.
Usage
as.includegraphics(object,
height="1em",
width=NULL,
wd=getwd(),
raise=NULL,
viewport=NULL, ## if specified, then left bottom right top.
## used for pdf png jpeg
bb=NULL, ## if specified, then left bottom right top.
## used for bmp tiff
trim="0 0 0 0", ## left bottom right top
clip="true"
)
Arguments
object
A character vector of filenames for files that contain graphics.
height
Character vector containing a LaTeX distance (by default "1em").
width
Character vector containing a LaTeX distance (by default NULL).
Keeping the default keeps the original aspect ratio.
Specifying a value will stretch the figure unless the height is set
to NULL.
wd
The directory in which the files reside. The default is the full path
to the current
working directory that R is using. The full path is necessary when
using the Hmisc::print.latex and related functions because they
run the operating system's latex or pdflatex command in
a temporary directory. The relative path to the current directory
(wd=".")
is sufficient if the file will be brought into a larger tex file
with the LaTeX input macro.
raise
Character vector containing a LaTeX distance (by default NULL).
This value may be negative. Use it if the default vertical
alignment of the graphs in the table is not satisfactory.
viewport
Size in pixels of the image file. This is the MediaBox
in a pdf file. It is the number reported by the operating system for a
png or jpeg file. The viewport is optional. When specified it must be a
character string containing four numbers in order: left, bottom, right, top.
bb
Bounding Box: Size in pixels of the image file. It is the number reported by the operating system for a
bmp or jpeg file. When specified it must be a
character string containing four numbers in order: left, bottom, right, top.
trim
Size in pixels to be trimmed. It must be a
character string containing four numbers in order:
left, bottom, right, top. See the manual for the LaTeX
package graphicx for details.
See the Details section for additional use of the trim argument.
clip
Character value "true" or "false".
Details
We recommend that the aspect ratio be controlled by the R functions
that generated the figure.
We recommend that only one of the arguments height and weight be used
in as.includegraphics. Using both will change the aspect ratio
and consequently stretch the figure. The trim argument is used
to remove excess margins from the figure.
Either the viewport or bb should be specified, not both.
The trim argument can be used to take apart an externally
produced graphics file and use its components in a LaTeX table.
See the files examples/irisSweaveTakeApart.Rtex and examples/irisSweaveTakeApart-Distributed.pdf for an example.
Value
A vector of LaTeX statements with the LaTeX macro includegraphics for
the input filenames.
Author(s)
Richard M. Heiberger <rmh@temple.edu>
See Also
latex, microplot
Examples
as.includegraphics("abc.pdf")
## [1] "includegraphics[height=1em]{/Users/rmh/abc.pdf}"
## This form, with the full pathname, is required when the Hmisc::print.latex
## and related functions are used to display the current .tex file on screen.
as.includegraphics("abc.pdf", wd=".")
## [1] "includegraphics[height=1em]{./abc.pdf}"
## This form, with the relative path, is optional when the .tex file will be
## embedded into a larger file, and will not be displayed on screen.
as.includegraphics(c("abc.pdf", "def.pdf"), raise="-1em")
## [1] "
aisebox{-1em}{includegraphics[height=1em]{/Users/rmh/abc.pdf}}"
## [2] "
aisebox{-1em}{includegraphics[height=1em]{/Users/rmh/def.pdf}}"
## Please see the package documentation ?microplot for a simple example in context.
## Please see the demos for more interesting examples.
## demo(package="microplot")