Learn R Programming

lazyWeave (version 3.0.2)

lazy.figure: Include Figures in Latex Documents

Description

Generates the code to place a figure in a Latex document

Usage

lazy.figure(filename, caption = NULL, align = "center", height = 3,
  width = 3, units = "in", counter, counterSet = NULL, label = NULL,
  placement = "h", alt = "Image Not Found",
  cat = getOption("lazyWeave_cat"))

Arguments

filename

Character string giving the location of the file to be included

caption

Text giving the caption for the figure

align

Character string stating the alignment. Valid options are "left", "right", or "center"

height

The height of the figure

width

The width of the figure

units

The units for height and width. Defaults to "in".

counter

Name of a counter to use to number the table

counterSet

The number to which counter should be set. In other words, the figure number for this figure

label

Name of a label

placement

Controls the placement of the figure. Options are "ht", "t", "b", "p", "H" and can be supplemented with "!". See "Details" for more explanation

alt

For HTML documents only--when filename cannot be found, this text is printed in the figure's place

cat

Logical. Determines if the output is returned as a character string or returned via the cat function (printed to console). The default value is set by options()$lazyWeave_cat. This argument allows for selective override of the default.

Details

For LaTeX files, placement options are used as follows:

ht Place the float here, i.e., approximately at the same point it occurs
t Position at the top of the page
b Position at the bottom of the page
p Put on a special page for floats only
H Places the float at precisely the location in the LaTeX code. Requires the float package

The "!" may be used after any of these in order to override LaTeX float rules and force your selection. More can be learned by reading about floats in a LaTeX manual.

For HTML files, the file can be any type supported by the browser. JPEGs and PNGs seem to work well.

Examples

Run this code
# NOT RUN {
pdf("MPG.pdf", height=4, width=4)
hist(mtcars$mpg)
dev.off()

lazy.figure("MPG.pdf")

lazy.write(
lazy.file.start(),
lazy.figure("MPG.pdf", 
caption="Distribution of Miles per Gallon in mtcars dataset",
height=5, width=5, label="MPGgraph"),
lazy.file.end(),
OutFile="Example-1.tex")

unlink("MPG.pdf")
unlink("Example-1.tex")
unlink("Example-1.pdf")
# }

Run the code above in your browser using DataLab