Description Usage Arguments Value Author(s) See Also Examples
This function acts as a front-end/wrapper function
for the corresponding function in the grDevices package.
The intent is that the caller both opens the device
and provides the commands to generate the entire plot within
this call.
This function creates the graphics device in the same way
the grDevices (or CairoSVG on windows) function does.
It then evaluates cmd
in order to generate the plot.
It then closes the graphics device and reads the SVG file
back into R using the XML
package.
It adds the text of the R command cmd
to the SVG file and writes that out again.
If addInfo
is TRUE
(and if the plot is a lattice plot)
it adds a great deal of meta-information to the SVG elements,
including details about the lattice plot
and also attempting to identify the type of each top-level element
within the top-most <g>
element in the SVG.
One can have the SVG document returned as a parsed XML document. This allows us to ignore the creation of the file and "pretend" that the SVG content is created directly in memory.
1 2 3 4 |
filename |
the name of the file to which the plot is written |
cmd |
the R expression generating the plot |
... |
any additional arguments to the grDevices |
asXML |
a logical value which indicates that whether the SVG document should be parsed and returned. The file is still created and left in place. |
print |
a logical value indicating whether we need to explicitly
print the result of |
removeFile |
a logical value indicating whether to delete the
file that was created by the |
addInfo |
a logical value that controls whether meta-information is added to the SVG document that both describes the plot and also attempts to identify the top-level SVG elements in the display. |
The value of filename
.
Duncan Temple Lang
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | doc = svgPlot(plot(1:10))
svgPlot({
plot(rnorm(100), col = c("red", "green"))
abline(v = 0, lwd = 2, lty = 3)
}, "tmp1.svg")
data(mtcars)
library(lattice)
pp = svgPlot(xyplot( mpg ~ wt | am + cyl, mtcars, group = carb,
auto.key = list(columns = 4, space ="right")))
getSVGNodeTypes(pp)
dim(pp)
x = getLatticeObject(pp)
# with a user-specified key.
o = svgPlot(xyplot( mpg ~ wt | am + cyl, mtcars, group = carb,
key = simpleKey(text = c("A", "B", "C"),
points = FALSE,
columns = 3)))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.