Author: DJ Rajdev
Contributors: Douglas Johnson
The significance of information visualization has been well-established over the last few years in the analytics and data science community. Owing to the wide variety of users and domains that are using data visualization, Spotfire offers multiple ways to create visualizations:
- Out of Box menu Visualizations: Spotfire provides an extensive list of visualizations that the user can configure right out of box. These can be linked to show detailed drill downs, combined with data generated dynamically from TERR, and controlled through filtering and marking settings.
- Create Open Source R Visualizations in Spotfire: Spotfire supports TERR (TIBCO Enterprise Runtime for R) and Open Source R through Data Functions, but often a user would want to create an R graphics using say ggplot2 library in Spotfire. The bulk of this article will focus on how-to embed R Graphics in a Spotfire Dashboard.
- Other methods to extend Spotfire visualizations may include working with Well Known Binary formats, particularly for Geoanalytics. These can be manipulated in data functions through TERR and plotted on map charts directly. TERR also includes options to create interactive plots in RStudio using libraries such as ‘ggvis’.
TIBCO Enterprise Runtime for R is a high-performance, enterprise-quality statistical engine to provide predictive analytic capabilities. TERR is available for integration into other applications through various APIs. Developing in R, and then deploying on TERR, lets you rapidly move from prototyping to production, without recoding and retesting your analyses.
Create a simple R graph in Spotfire
The package ‘RinR’ allows the user to run Open Source R code in TIBCO Enterprise Runtime for R or vice-versa. We’ll be making use of ‘RGraph’ function from ‘RinR’ to create a graphic in OSR and pass it to TERR to display in Spotfire.
- Install ‘RinR’ in TERR (tutorial)
- Install the graphics package (say ggplot2, ggally etc.) in Open Source R
- Optional. Download the sample heightweight dataset and read in using ‘load()’. This will be stored in Table1 for the scripts below.
Try it in RStudio with Open Source R
The following sample script creates a matrix of plots
library(GGally) ggpairs(data = Table1, columns=c(1,3:6))
Set up Data Function
# @Author: DJ Rajdev # @Purpose: Sample RGraph creation library(RinR) outputPlot1 <- RGraph( print( ggpairs( data = Table1, columns=c( 1,3:6 ) ) ), packages='GGally', data='Table1' )
Ensure data function is executing in TERR
Define Input and Output Parameter
Run data Function
This registers it to the list of data Functions. You can also save this to library
Connect Input and Outputs
Input - the data table:
Output - document property RGraphPackage:
In a text area include the Document Property RGraphPackage as a ‘Label’ type property control
This displays the resulting graph in a text area.
How the Script works
‘RGraph’ gets the graph from OSR in binary format that can then be stored as a binary value in a Document Property and displayed in a text area. ‘data’ is used to specify the data table being referenced within the graphing commands and ‘packages’ tells OSR which packages to invoke- this argument can take a vector.
RinR can be used to rapidly prototype R models and display ggplot results as below or rapidly create color palettes for Spotfire.
Using RGraphics in webplayer
In the webplayer RinR would work via a TSSS instance that uses TERR as its statistical engine. Follow the steps to create RGraphics in Spotfire text areas in webplayer:
- Download and install a compatible open-source R instance on the server that hosts the TSSS/TERR instance
- Provide the path to that open-source R instance for use in calls to RinR::RGraph()
- Any CRAN packages that are needed inside calls to RGraph() will need to be installed in the open-source R instance on the TSSS server
- No additional CRAN packages are needed
The example in this public KB article can be used for testing the setup.
How do I learn more?
This summarizes how to create R graphics in Spotfire. Watch the page and vote up to get notified about detailed updates. You could also request a featured session on any specific method from above on Dr. Spotfire by:
- Tweeting your question with the hashtag #DrSpotfire
- Posting your question to the TIBCO Community "Answers" section with the hashtag #DrSpotfire
- Contact Dr. Spotfire directly at email@example.com