Learn R Programming

Kmisc (version 0.5.0)

hImg: Print Plot to File and Return HTML

Description

A convenience function that prints a plot to file, and then returns HTML to embed that image in the page.

Usage

hImg(my_plot, file, width = 400, height = 300, dpi = 300, dim = NULL, scale = 100, device = "png", ...)

Arguments

my_plot
a plot object, or code that generates a plot
file
file location to output image to
width
width (in pixels) of the plot
height
height (in pixels) of the plot
dpi
the number of dots per inch used. Default is high to ensure plots are crisp on all displays
dim
passed to par( mfrow ); used if making multiple base-R plots
scale
the scale factor to use when scaling plots for web display.
device
the device to use for the plot call.
...
optional arguments passed to png

Details

The dim attribute is passed on to par( mfrow='dim' ); ie, it is used if you are calling a plot function that writes more than one plot.

The png device is used.

Examples

Run this code
library(lattice)
## generate an xyplot, write it to file, and return HTML
## code that sources the generated image
dat <- data.frame( x = rnorm(100), y = rnorm(100) )
hImg( file = "plot_output.png",
  xyplot( y ~ x, dat )
)

Run the code above in your browser using DataLab