RpadGraphing {Rpad}R Documentation

Rpad graphing utilities

Description

Utilities to make graphing in Rpad R scripts easier.

Usage

  graphoptions(..., reset = FALSE, override.check = TRUE)
  newgraph(name = "", extension = graphoptions()$extension,
     type = graphoptions()$type, res = graphoptions()$res,
     width = graphoptions()$width, height = graphoptions()$height,
     deviceUsesPixels = graphoptions()$deviceUsesPixels,
     pointsize = graphoptions()$pointsize, sublines = graphoptions()$sublines,
     toplines = graphoptions()$toplines, ratio = graphoptions()$ratio,
     leftlines = graphoptions()$leftlines, lwd = graphoptions()$lwd, ...)
  showgraph(name = RpadPlotName(), link = FALSE, ...)
  RpadPlotName()

Arguments

reset, override.check logical arguments passed to check.options.
name is the name of the graph with the extension left OFF.
extension is the file extension of the device (typically '.png').
type is the graphics device, either a ghostscript device as a character string, "Rpng" for R's builtin png device, or any R graphics device function. For a ghostscript device, common possibilities are "png256", "pngalpha" (the default), or "pdf".
res is the resolution of the bitmap in dots per inch.
width, height are the dimensions of the graph in inches.
deviceUsesPixels is a logical specifying whether the R graphics driver uses pixels. This only applies if type is used to specify an R graphics driver. It defaults to TRUE.
ratio specifies the ratio of the graph if either the width or height is not specified.
pointsize is the font point size passed to the postscript device.
sublines, toplines, leftlines specify the dimension of the graph along with the outside border. It defaults to fairly tight outside dimensions.
lwd is the line width set with par.
link is a logical specifying whether to show a link to allow the user to download an EPS file of the graph (not available when using R's png driver.
... in fspdf and newgraph, arguments are passed to postscript. In graphoptions, the arguments are assigned as defaults for newgraph.

Details

The graphoptions, newgraph, and showgraph set of functions allows quick setup and display of web-friendly graphics. The user can normally just use any of the plot commands followed by showgraph. newgraph sets up the graphics device, and it's called when the Rpad package starts. showgraph generates the HTML to show the graph and runs newgraph to advance to the next graphics file. The user only runs newgraph to change parameters from their defaults. Graphics files are by default named Rpad_plot1, Rpad_plot2, and so on. Named graphs can also be used, but there's more of a chance that if the user has caching set wrong (or the server's caching is set wrong) that graphs won't update properly in the user's browser. With the default sequential numbering of files, caching problems are less likely. graphoptions is also available to change the defaults for subsequent graphs.

Internally, newgraph uses the postscript device and ghostscript to generate the bitmap for the browser. The pngalpha (type="pngalpha") device of ghostscript does anti-aliasing for smoother-looking PNG output. Also, this approach has the side-effect of creating an EPS file for each graph, so it's easy to add a link to allow the user to download the EPS file. A second approach is to use R's png device directly by specifying type="Rpng" (but on linux, this requires an X server, and results are not antialiased). A third approach allows arbitrary R graphic's devices to be specified. Simon Urbanek's GDD or Cairo packages can be used to generate png (for both packages, see http://www.rosuda.org/R/). This allows high-quality png generation with anti-aliasing, and you don't need ghostscript or X11.

Value

RpadPlotName() returns the name of the currently active plot. None of the other routines return a value: all are run for their side effects.

Author(s)

Tom Short, EPRI, (tshort@epri.com)

See Also

See also bitmap, png, and pdf.

Examples

# make some graphs (a default graphics device is already available)
  x <- 1:10
  y <- x^2
  y2 <- x^3
  if (capabilities("png")) graphoptions(type="Rpng")
  newgraph()
  plot(x, y)  # does the plot
  plot(x, y2) # does the second plot
  HTMLon()    # sets Rpad to HTML output
  showgraph() # closes the device, outputs the HTML for the both
              # images, and creates the next device
  plot(x, y2)
  showgraph()

# graphs with named files:
  newgraph("graph_A")
  plot(x, y)
  showgraph("graph_A")
  newgraph("graph_B", width = 4, height = 6) # also adjust the width and height
  plot(x, y2)
  showgraph("graph_B")

# an example with Simon Urbanek's GDD device:
  if (require(GDD)) {
    graphoptions(type = GDD, width = 4, height = 3) # note the use of inches
    newgraph()
    plot(x, y)
    plot(x, y2)
    showgraph()
  }

[Package Rpad version 1.3.0 Index]