Interactive Plots with Gadfly, Interact, and IJulia


In [6]:
using RDatasets
ggdat = RDatasets.datasets("ggplot2") # convenient way to list datasets for a package


Out[6]:
PackageDatasetTitleRowsColumns
1ggplot2diamondsPrices of 50,000 round cut diamonds5394010
2ggplot2economicsUS economic time series.4786
3ggplot2midwestMidwest demographics.43728
4ggplot2moviesMovie information and user ratings from IMDB.com.5878824
5ggplot2mpgFuel economy data from 1999 and 2008 for 38 popular models of car23411
6ggplot2msleepAn updated and expanded version of the mammals sleep dataset.8311
7ggplot2presidentialTerms of 10 presidents from Eisenhower to Bush W.104
8ggplot2sealsVector field of seal movements.11554

Note that we can extract the dataset names as a DataArray


In [7]:
ggdat[:Dataset]


Out[7]:
8-element DataArray{UTF8String,1}:
 "diamonds"    
 "economics"   
 "midwest"     
 "movies"      
 "mpg"         
 "msleep"      
 "presidential"
 "seals"       

using Interact

Interact.jl provides "shiny-like" HTML widgets that gives us the ability to do "indirect manipulation" inside an IPython notebook. Interact.jl is built on top of Reactive.jl -- a general framework for reactive programming.


In [8]:
using Interact
@manipulate for dataName = ggdat[:Dataset] # Interact's widget defaults are based on variable types
    dat =  dataset("ggplot2", dataName)
end


Out[8]:
CaratCutColorClarityDepthTablePriceXYZ
10.23IdealESI261.555.03263.953.982.43
20.21PremiumESI159.861.03263.893.842.31
30.23GoodEVS156.965.03274.054.072.31
40.29PremiumIVS262.458.03344.24.232.63
50.31GoodJSI263.358.03354.344.352.75
60.24Very GoodJVVS262.857.03363.943.962.48
70.24Very GoodIVVS162.357.03363.953.982.47
80.26Very GoodHSI161.955.03374.074.112.53
90.22FairEVS265.161.03373.873.782.49
100.23Very GoodHVS159.461.03384.04.052.39
110.3GoodJSI164.055.03394.254.282.73
120.23IdealJVS162.856.03403.933.92.46
130.22PremiumFSI160.461.03423.883.842.33
140.31IdealJSI262.254.03444.354.372.71
150.2PremiumESI260.262.03453.793.752.27
160.32PremiumEI160.958.03454.384.422.68
170.3IdealISI262.054.03484.314.342.68
180.3GoodJSI163.454.03514.234.292.7
190.3GoodJSI163.856.03514.234.262.71
200.3Very GoodJSI162.759.03514.214.272.66
210.3GoodISI263.356.03514.264.32.71
220.23Very GoodEVS263.855.03523.853.922.48
230.23Very GoodHVS161.057.03533.943.962.41
240.31Very GoodJSI159.462.03534.394.432.62
250.31Very GoodJSI158.162.03534.444.472.59
260.23Very GoodGVVS260.458.03543.974.012.41
270.24PremiumIVS162.557.03553.973.942.47
280.3Very GoodJVS262.257.03574.284.32.67
290.23Very GoodDVS260.561.03573.963.972.4
300.23Very GoodFVS160.957.03573.963.992.42
&vellip&vellip&vellip&vellip&vellip&vellip&vellip&vellip&vellip&vellip&vellip

Gadfly


In [11]:
using Gadfly
diamonds = dataset("ggplot2", "diamonds");
set_default_plot_size(16cm, 12cm);

In [12]:
@manipulate for xn = 10:100, yn = 10:100
    plot(diamonds, x = "Carat", y = "Price", Geom.hexbin(xbincount = xn, ybincount = yn))
end


plot not defined
while loading In[12], in expression starting on line 1

 in anonymous at no file:2

In [ ]: