Loon: An Interactive Statistical Visualization Toolkit

Introduction

loon is written in Tcl and Tk, and the loon R package provides a thin layer of R code to embed loon into the R environment.. Tcl is a programming language and Tk is a GUI toolkit written as an extension for Tcl.

Knowledge of Tcl and Tk are not required to use loon in R. However, a basic understanding of Tcl and Tk helps to appreciate certain API design decisions and, it also helps to follow some advanced topics such as event bindings and widget layout with geometry management. Hence, you may read our short overview of tcltk R package.

If your knowledge of R is generally basic, then consider reading the slides from the R introduction course written by Adrian Waddell.

Installation

See the beta section.

Getting Started

The following R code provides a short loon sample session

# Load the library
library("loon")

# Create a scatterplot
p <- with(iris, l_plot(x=Sepal.Width, y=Sepal.Length, color=Species,
  linkingGroup="iris"))

# Create a histogram
h <- l_hist(x=iris$Petal.Width, linkingGroup="iris")

# Query a plot state
p['color']

# Modify a plot state
p['size'] <- iris$Petal.Length

The user interfaces of loon's displays are explained in the UI section.

Package Demos

The loon R package comes with many demos that show how to use particular parts of the loon API. See,

demo(package = "loon")

Run a particular demo as follows

demo("l_us_and_them_choropleth")

To get the location of the source code of a particular demo (e.g. l_us_and_them_choropleth) use

system.file("demo", "l_us_and_them_choropleth.R", package = "loon")

Re-creating Object Handles

It is possible to re-create any loon object handle in an R session. That is, handles for displays, layers, glyphs, navigators and context handles can be created with the widget path name and the appropriate ids. The object handle can then be used with the methods [ and [<- to access and modify states. For example, for a display with the widget path name .l1.hist one can create a loon plot handle as follows

h <- '.l1.hist'
class(h) <- 'loon'  

For a layer with the layer id layer23 of that display the layer handle can be created as follows

l <- 'layer23'
class(l) <- c('loon', 'l_layer')
attr(l, 'widget') <- '.l1.hist' 

For a context with the id context0 of a navigator with id navigator1 of a graph with widget path name .l4.graph, the context handle is created as follows:

con <- 'context0'
class(con) <- c('loon', 'l_context')
attr(con, 'widget') <- '.l4.graph'
attr(con, 'navigator') <- 'navigator1' 

and so on. The l_cget and l_configure have target as their first argument which either accepts a loon object handle or a vector with the widget path name and the object ids. The following code blocks have each two lines that do the same

l_configure(h, color='red')
l_configure('.l1.hist', color='red')
l_configure(l, color='green')
l_configure(c('.l1.hist', 'layer23'), color='green')
l_configure(con, command='')
l_configure(c('.l4.graph', 'navigator1', 'context0'), command='')

The re-creation of object handles is useful when, for example, an object handle is lost or overwritten.

A Couple of Notes

loon's l_plot and l_hist functions are similar to use as R's base graphic function plot. This is because we use the R function xy.coords to extract the coordinates from x and y. For example for

l_plot(c(1,2,3), c(4,2,4), cex=c(4,1,8), col=c('red','blue','yellow'))
with(mtcars, l_plot(hp ~ wt))

the l_plot function call could be replaced with plot for non-interactive equivalents using R's base graphics. Note that loon will generate warnings if you use some base R graphics argument names instead of loon's state names (e.g. col vs color or lwd vs linewidth).

Also,