Interactive and Animated Scalable Vector Graphics and R ... › publication › fulltext › Interactive... › publication › fulltext › Interactive...by D Nolan · Cited by 18 · Related articlesTutorial], and in this article, we describe an approach within R [2
1. Introduction The way we view graphical representations of data has significantly changed in recent years. For example, viewers expect to interact with a graphic on the Web by clicking on it to get more information, to produce a different view, or control an animation. These capabilities are available in Scalable Vector Graphics (SVG) [1, W3 Schools SVG Tutorial], and in this article, we describe an approach within R [2] to creating stand-alone interactive graphics and animations using SVG. SVG offers interactivity and animation through a rich set of elements that allow the graphics objects to be grouped, styled, transformed, composed with other rendered objects, clipped, masked, and filtered. SVG may not be the most ideal approach to interactive graphics, but it has advantages that come from its simplicity and increasing use on the Web and publishing generally. The approach presented here uses R's high-level plotting functions, R's SVG graphics device engine and the third-party cairo rendering engine [18] to create high-quality plots in SVG. Our tools then allow users to post-process the SVG documents/plots to provide the additional annotations to make the document interactive, e.g. users can add hyperlinks, tool tips, linked plots, controls (sliders and buttons), and animation to these displays to create potentially rich, compelling graphical displays that can be viewed outside of the R environment. The SVGAnnotation package [17] contains a suite of tools to facilitate the programmer in this process. The package uses the XML [ Open XML] parsing and writing facilities in the XML package [16] to provide “high-level” facilities for augmenting the SVG output from the standard plotting functions in R, including lattice [20] and the traditional grzmodel plotting functions in R. In addition to providing useful higher-levels facilities for modifying the more common R plots, the SVGAnnotation package also provides many utilities to handle other types of plots, e.g. maps and graphs. Of course, it is possible to generate interactive graphics from “scratch” by taking charge of all drawing, e.g. determining the coordinate system and drawing the axes, tick marks, labels, etc. However for complex data plots, we are much better off using this post-processing approach and leveraging R's excellent existing graphics facilities. We do not want to suggest that the approach presented here is the definitive or dominant solution to the quest for general interactive graphics for R or statistics generally. Our focus is on making graphical displays created in R available in
1
Interactive and Animated Scalable Vector Graphics and R Data Displays
new ways to different audiences outside of R and within modern multi-media environments. This approach works well in many cases, and the XML tools in XML make it an alternative that we believe is worth exploring. While the popularity or uptake of this approach may be debatable due to prospects of SVG or implementations of the complete SVG specification in widely used browsers, what we have implemented can be readily adapated to other formats such as Flash or the JavaScript canvas. Hence this paper also provides ideas for future work with other similar graphical formats such as Flash and Flex MXML [28] and the JavaScript canvas. The essential idea is to post-process regular R graphics output and identify and combine the low-level graphical objects (e.g. lines and text) into higher-level components within the plot (e.g. axes and labels). Given this association, we can then annotate components to create interactive, dynamic and animated plots in various formats. The remainder of the paper is organized as follows. We start by explaining reasons why SVG is a valuable format. We then give a brief introduction to several examples that we use throughout the document. These illustrate different features of SVG and how they might be used for displaying statistical results. We then introduce the common elements of SVG and examine the typical SVG document produced when plotting in R. From there we move on to explore general facilities that one may use to add to an SVG plot generated within R. The examples serve as the context for the discussion of these functions and the general approach. The facilities include adding tool tips and hyperlinks to elements of a display and more advanced features that deal with non-standard R displays and animation. We also show how one can add GUI components directly in SVG and alternatively use HTML forms with SVG. Additionally, we illustrate aspects of integrating JavaScript and SVG. We conclude the paper by discussing different directions we are exploring in this general area of stand-alone, interactive, animated graphics that can be displayed on the Web. We discuss several technologies in this paper which may be new to readers. We provide an introduction to XML and also to JavaScript in two appendices. It may be useful for some readers to review these before reading the rest of this paper. We also note that this paper can be viewed as an HTML document (at http://www.omegahat.or