Learn R Programming

FastRWeb (version 1.2-1)

WebPlot: Graphics device for inclusion of plots in FastRWeb results.

Description

WebPlot opens a new graphics device (currently based on Cairo) and returns an object that can be used as a result of FastRWeb functions or in web output.

Usage

WebPlot(width = 640, height = 480, type = "png", ...)

Value

WebPlot object.

The structure of the WebPlot class is considered internal and should not be created directly. Current attributes include

file (filename), type (output type), mime (MIME type), width, height.

Arguments

width

width of the resulting plot (normally in pixels)

height

height of the resulting plot (normally in pixels)

type

type of the output

...

furhter arguments to be passed to Cairo

Author

Simon Urbanek

Details

WebPlot generates a temporary file name that is accessible using the "tmpfile" command of WebResult and opens a new Cairo device with the specified parameteres. It returns a WebPlot object that can be either retured directly from the run() function (and thus resulting in one image) or used with the out() function to reference the image in an HTML page (see examples below).

Note that as.WebResult coercion is used to finalize the result when returned directly and it will close the device, so dev.off() is optional and not needed in that case. Also WebPlot reserves the right to close any or all other active WebPlot devices - this ensures that dev.off() may not be neeed at all even when using multiple WebPlots.

See Also

WebResult

Examples

Run this code
## example 1: single image
## if saved as "plot.png.R"
## it can be served as http://server/cgi-bin/R/plot.png
run <- function(n = 100, ...) {
  n <- as.integer(n)
  # create the WebPlto device
  p <- WebPlot(800, 600)
  # plot ...
  plot(rnorm(n), rnorm(n), pch=19, col="#ff000080")
  # return the WebPlot result
  p
}

## example 2: page containing multiple images
## if saved as "plotex.html.R"
## it can be served as http://server/cgi-bin/R/plotex.html
run <- function(...) {
  out("Simple example")
  data(iris) ## ideally, you'll use data from the Rserve session
  attach(iris)
  p <- WebPlot(600, 600)
  plot(Sepal.Length, Petal.Length, pch=19, col=Species)
  out(p)
  p <- WebPlot(350, 600)
  barplot(table(Species), col=seq.int(levels(Species)))
  out(p)
  done()
}

Run the code above in your browser using DataLab