[R] convert R plots into annotated web-graphics

Duncan Temple Lang duncan at wald.ucdavis.edu
Tue Feb 9 13:46:46 CET 2010


Hi

While there is different level of support for SVG in the different browsers,
basic SVG (non-animation) does work on all of them (with a plugin for IE).

In addition to the 2 SVG packages on CRAN, there is SVGAnnotation at
www.omegahat.org/SVGAnnotation and that is quite a bit more powerful.
There is a link on that page to some examples that are similar to yours.

Imagemaps are a perfectly good way of achieving the interactivity you describe and Barry's
imagemap package should make this pretty straightforward.
If all you need is to have event handlers for regions, then imagemaps will be fine.
And some JavaScript code will allow you to connect the image map events to changing
characteristics of the table.

The rest of this mail is about richer approaches

However, there are other styles of interaction and animation that require working at the level of objects on the plot,
i.e. points, lines, text, etc.  When we have these objects at rendering time rather than pixels and regions,
we can, e.g., change the color of a point, changing its appearance (color or size), hide or move a point, etc.
You need this to do linked plots, for example, i.e. where we mouse over a point in one plot or the data table
and highlight the corresponding observations in other plots.

If you want this richer framework, you can generate the plot in R in such a way that it will be
displayed in your browser not as a PNG file, but with real objects being created within the
rendering.  The SVGAnnotation package does this reasonably comprehensively.

You can generate a plot in R that will be displayed on the JavaScript canvas.
Again, this will create objects and they can then be manipulated by JavaScript
event handlers that work on the plot elements and the table.
There is a prototype  of such an R-JavaScript canvas graphics devices
in the RGraphicsDevice package at www.omegahat.org/RGraphicsDevice.

Also, there is a beta-level Flash device that works at the object level and
allows an R programmer to annotate the resulting plot in either R or ActionScript.
(This is at www.omegahat.org/FlashMXML.)
There is another Flash graphics device for R at
    https://r-forge.r-project.org/projects/swfdevice/
but this doesn't work at the object-level (at this point in time, at least).


Both the FlashMXML and JavaScript packages rely on the RGraphicsDevice
package and that could be fixed up minorily to handle font metric calculations
with more accuracy (e.g. using RFreetype).


Instead of using an HTML table and modifying it programmatically via CSS
properties, etc., you might use a widget.

   a DataTable widget from the Yahoo UI javascript library.
   a Flash DataGrid to display the data as an interactive table.


As I said, image maps are probably simplest if your needs are reasonably simple.
These other approaches allow for potentially richer Web-based graphics.



Barry Rowlingson wrote:
> On Sun, Feb 7, 2010 at 2:35 PM, Rainer Tischler <rainer_t62 at yahoo.de> wrote:
>> Dear all,
>>
>> I would like to make a large scatter plot created with R available as an interactive web graphic, in combination with additional text-annotations for each data point in the plot. The idea is to present the text-annotations in an HTML-table and inter-link the data points in the plot with their corresponding entries in the table, i.e. when clicking on a data point in the plot, the corresponding entry in the table should be highlighted or centered and vice-versa, when clicking on a table-entry, the corresponding point in the plot should be highlighted.
>>
>> I have seen that CRAN contains various R-packages for SVG-based output of interactive graphics (with hyperlinks and tool-tip annotations for each data point); however, SVG is not supported by all browsers. Is anybody aware of another solution for this problem (maybe based on image-maps and javascript)?
>> If you have alternative ideas for interlinking tabular annotations with plotted data points, I would appreciate any recommendation/suggestion.
>> (I work with R 2.8.1 on different 32-bit PCs with both Linux and Windows operating systems).
>>
> 
>  My 'imagemaps' package?
> 
> https://r-forge.r-project.org/projects/imagemap/
> 
> Barry
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list