6 June 2014

Interactive Visualization Examples (Not in R!)


An interactive map for Indian Pincode.

Explorable Explanation

An audio processing example which allows for exploration in parametric, symbolic, diagramatic and visual ways.


The smartphone, tablets and PCs installed base as interactive barchart and mosaic charts.

What is Interaction?

Conceptual Model <—> Real World

Reduce the Gulf of Execution & Gulf of Evaluation between these two.

Gulf of Execution

The difference between the user’s intentions and the allowable actions.

Gulf of Evaluation

The amount of effort that the person must exert to interpret the state of the system and to determine how well the expectations and intentions have been met.

Reference: The Design of Everyday Things - Don Norman

Interaction Techniques for EDA

  • Navigation: Pan, Zoom, Scale, Rotate
  • Selection / Annotation: View specification e.g. map data to visual variables
  • Filtering: Highlighting, Brushing & Linking e.g. selecting a subset of data
  • Sorting: Conditional Panels / Facets
  • Dynamic Queries: Extract Data

Explore binwidth interactively?

ggplot(diamonds, aes(price)) + geom_histogram(binwidth = 500)

plot of chunk binwidth

Find the outliers?

ggplot(diamonds, aes(carat, price)) +

plot of chunk outlier

Static vs. Interactive Visualization in R

Static Graphics

  • Strong inbuilt plot package - graphics
  • Mature package options - grid, lattice, ggplot2
  • Can all be run in basic R
  • Easily installed through CRAN

Interactive Graphics

  • Limited (nearly no!) inbuilt support
  • Packages in varying (early) stages of development
  • Require integration with additional GUI
  • Not all easy installed

Interactive Graphics Options in R

Within R - identify()

Use pointing to identify points in a scatter plot and put label them.

# Identify point in a scatterplot 
plot(mpg, wt) 
identify(x = mpg, y = wt, n = 3, label = row.names(mtcars))

Within R - locator()

Used to read the position of the graphics cursor (when the mouse pressed). Those positions will be then plotted as points or joined by lines.

# Locate points on a scatterplot 
plot(mpg, wt) 

# draw up to 3 points
locator(n = 3, type="p") 

# draw up to 4 points joined by lines
locator(n = 4, type="l")

manipulate in RStudio

Takes a plotting expression and a set of controls (e.g. slider, picker, checkbox, or button) to dynamically change values within the expression.

When a value is changed using its corresponding control the expression is automatically re-executed and the plot is redrawn.

manipulate(ggplot(diamonds, aes(price)) + 
        geom_histogram(binwidth = bin), 
        bin=slider(40, 500))


A general purpose statistical data-visualization system written in JAVA. Available as R package called "iplots", though needs Java Gui for R (JGR) instead of RStudio for full functionality.

  • Works with tsv and csv files and loads data from R workspace.

  • Excellent interactive visualization techniques for data of almost any kind, including Categorical Data, Geographical Data and LARGE Data.

  • Fully linked plots, and offer many interactions and queries. Any case selected in a plot in Mondrian is highlighted in all other plots.

  • Currently implemented plots comprise Histograms, Boxplots y by x, Scatterplots, Barcharts, Mosaicplots, Missing Value Plots, Parallel Coordinates/Boxplots, SPLOMs and Maps.


Save the diamonds dataframe


Download and install Mondrian from http://rosuda.org/mondrian/

Load the diamonds.RData file and start exploring


Builds interactive web applications from R.

Each Shiny App has two components:

  • User Interface Script (ui.R): Controls the layout and apperance of the script
  • Server Script (server.R): Containes the reactive control logic to recreate the output, when the input variables are changed

Any one with the files ui.R and server.R can run the visualization inside R Studio

Create your Shiny Projects - ui.R

# This is the server logic for a Shiny web application.

shinyServer(function(input, output) {
  output$distPlot <- renderPlot({
    # generate bins based on input$bins from ui.R
    x    <- faithful[, 2]
    bins <- seq(min(x), max(x), length.out = input$bins + 1)

    # draw the histogram with the specified number of bins
    hist(x, breaks = bins, col = 'darkgray', border = 'white')


Create your Shiny Projects - server.R

# This is the user-interface definition of a Shiny web application.

  # Application title
  titlePanel("Old Faithful Geyser Data"),

  # Sidebar with a slider input for number of bins
      sliderInput("bins", "Number of bins:",
                  min = 1, max = 50, value = 30)),
    # Show a plot of the generated distribution


You can share your shiny files and anyone can run it in RStudio.

To make it accesible to everyone without RStudio, you need a Shiny Server to host the files.

Free hosting (at the moment) at https://www.shinyapps.io/

Diamonds dataset hosted on shinyapps

Diamonds Explorer


To create, customize and publish interactive javascript visualizations from R using a lattice style plotting interface

install_github('rCharts', 'ramnathv')

hair_eye_male <- subset(as.data.frame(HairEyeColor), 
                        Sex == "Male")
n1 <- nPlot(Freq ~ Hair, group = "Eye", 
            data = hair_eye_male, type = "multiBarChart")

Quick Start Guide


Creates web pages with interactive charts based on R data frames, using the Google Chart Tools.

Display them either via the local R HTTP help server or within their own sites, without uploading the data to Google.

plot(gvisMotionChart(Fruits, "Fruit", "Year"))

## Can create the gapminder type graphs
## Caution: Takes a long time to load


  • Interactivity in R Graphics is rapidly developing. Keep track of developments across packages.

  • Good visualizations are task dependent. Design for the data and domain.

  • Think what interactions would be helpful to explore the data: Navigation, Selection / Annotation, Filtering, Sorting, Dynamic Queries