hImg: Print Plot to File and Return HTML

Description Usage Arguments Details Examples

View source: R/html_extras.R

Description

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

Usage

1
2
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

1
2
3
4
5
6
7
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 )
)

kevinushey/Kmisc documentation built on May 20, 2019, 9:08 a.m.