d3Device: Create a graphics device to generate D3 code

Description Usage Arguments Value Author(s) References See Also Examples

Description

d3Device creates a graphics device instance. All graphics commands sent to this device will generate JavaScript code that will render the plot when viewed in a Web browser. The JavaScript code uses D3 to render the graphical elements.

d3Plot is a wrapper function that atomically creates a D3 device, evaluates the specified commands to generate a graphical display and then closes the device.

Usage

1
2
3
d3Device(dim = c(800, 600), file = character(), svgVarName = "svg",
         div = "svg", plotVarName = sprintf("_%s", svgVarName))
d3Plot(expr, file = character(), ...)

Arguments

dim

a vector of two numbers specifying the width and height of the graphics canvas. The values are number of pixels.

file

the file to which the D3 JavaScript code will be written. This can be omitted and one can retrieve the code after closing the device and then post-process it to, for example, add interactivity.

svgVarName

the name of the JavaScript variable to which the top-level D3 object for the plot is assigned. This is different from the plot object which maintains references to the different types of graphical elements.

div

the name of the HTML element in which D3 will add the SVG elements

plotVarName

the name of the JavaScript variable to which the plot object will be assigned. We can use this variable to add JavaScript code to process elements of the plot.

expr

the R code to create the entire display

...

additional arguments passed to d3Device

Value

d3Device creates a new graphics device and makes it active.

Both functions return a list with the following elements:

dev

a reference to the C-level DevDesc object

device

a RDevDescMethods object which contains the functions used to implement the graphics primitives.

getCode

a function that returns the JavaScript code generated by the device

getCalls

a function that returns the R call stack for each object. This allows us to heuristically determine the purpose of each graphical element, e.g. a line created in a call to axis, or tex in a call to legend.

getJSInfo

a function that returns information about the generated JavaScript code, i.e. the names of the JavaScript variables (svgVarName, plotVarName, divName)

getCode and getCalls are functions that we call after we have finished creating the graphical display. These return information about the graphical elements that were generated by the R graphics engine. The plot is not actually rendered at this point in that the JavaScript code has not been evaluated. That is done outside of R in a Web browser. However, these functions return details about those graphical elements that will be created in JavaScript.

Author(s)

Duncan Temple Lang

References

R graphics devices, D3

See Also

RGraphicsDevice package

addToHTMLTemplate

Examples

1
2
3
4
dev = d3Device()
plot(1:10)
dev.off()
dev$getCode()

duncantl/RD3Device documentation built on May 15, 2019, 5:28 p.m.