Interactive Charts

Open-source data visualisations

I'm sharing some inspiring visualisations I explored with workshop participants at a datavis workshop in Ghana this week. They provide an overview of popular software packages for interactive graphs.

See here for the course materials.


Overview

For other R libraries, see leaflet, htmlwidgets, plotly and useful tutorials on data visualisation in R at flowingdata.com.

Many of the packages below require that you have Rtools installed in addition to base R. I also recommend using RStudio as a front end.


A. The rCharts package

The rCharts package allows you to create, customize and publish interactive javascript visualizations from R using a lattice style plotting interface.

To get started, open R and install and load the package as follows.

library(devtools)
install_github('ramnathv/rCharts')

Then you can start exploring the examples using pre-loaded datasets or your own data. For more examples, check out the rCharts gallery.


A.1. Population pyramid
library(rCharts)
source('http://klein.uk/R/Viz/pyramids.R')

## Select population counts for Qatar in 2014
dat <- getAgeTable2(country='QA', year=2014)
head(dat)
Year Age total Male Female percent pctMale pctFemale sexratio ord
2 2014 0-4 101272 51253 50019 4.8 3.1 10.3 102.5 1
3 2014 5-9 88869 45308 43561 4.2 2.8 9.0 104.0 2
4 2014 10-14 74976 37916 37060 3.5 2.3 7.6 102.3 3
5 2014 15-19 87906 55349 32557 4.1 3.4 6.7 170.0 4
6 2014 20-24 196261 152929 43332 9.2 9.3 8.9 352.9 5
7 2014 25-29 322775 259540 63235 15.2 15.8 13.0 410.4 6
n1 <- nPyramid(dat, colors = c('darkred', 'silver'))
n1


Back to top


A.2. Data table
## Load data
SchoolsGroup <- read.csv("https://raw.github.com/patilv/rChartsTutorials/master/SchoolsGroup.csv")
head(SchoolsGroup)
X Group.1 Group.2 Group.3 Group.4
1 Texas Cincinnati Kentucky Bowling Green
2 Ohio State Memphis Louisville William & Mary
3 Michigan Air Force South Carolina Montana
4 Alabama South Florida Minnesota North Dakota
5 Florida Boise State Washington South Alabama
6 Texas A&M New Mexico North Carolina Maine
## Load styles
tab2 <- dTable(SchoolsGroup[,-1], sPaginationType = "full_numbers")
tab2$templates$script <- "http://timelyportfolio.github.io/rCharts_dataTable/chart_customsort.html" 

## Set column names
tab2$params$table$aoColumns =
  list(
    list(sType = "string_ignore_null", sTitle = "Group 1"),
    list(sType = "string_ignore_null", sTitle = "Group 2"),
    list(sType = "string_ignore_null", sTitle = "Group 3"),
    list(sType = "string_ignore_null", sTitle = "Group 4")
  )

## Produce data table
n1 <- tab2
n1