Fork me on GitHub

I have enjoyed watching the development of ggvis. A while back I wanted to understand the inner workings of ggvis, so I hacked together a combination of Vega Live Editor, rCharts, and Ramnath Vaidyanathan's Live rCharts editor to play with the underlying ggvis spec. Now that ggvis has reached a level of maturity for it to reach CRAN, I thought it might be helpful to share the interactive playground using Scatterplot Example 3 from the ggvis cookbook.

You can run all of the examples in the playground from the ggvis cookbook with this code.R.

Load All of Our Packages

require(ggvis)
require(dplyr)
require(shiny) #need shiny isolate function for as.vega

#build a rCharts wrapper
require(rCharts)
options( viewer=NULL )

Build an rCharts Wrapper

rCharts_vega <- setRefClass(
  "rCharts_vega",
  contains = "rCharts",
  methods = list(
    initialize = function(){
      callSuper(); 
    },
    getPayload = function(chartId){
      list(
        chartParams = RJSONIO::toJSON(params),
        chartId = chartId,
        lib = basename(lib), 
        liburl = LIB$url
      )
    })
)

vPlot <- rCharts_vega$new()
vPlot$setLib( "." )
vPlot$templates$script = "./chart_vega.html"
vPlot$set(
  bodyattrs = "ng-app='myApp' ng-controller='MainCtrl'"
)
vPlot$setTemplate(
  chartDiv = "<div></div>"
)
vPlot$setTemplate(
  afterScript = "
  <script>
  </script>     
  "
)

Scatterplots Example 3

# with examples from help/library/ggvis/doc/cookbook.html

vPlot$params$spec <- mtcars %>% 
  ggvis(~wt, ~mpg) %>%
  layer_points() %>%
  layer_smooths() %>%
  ggvis:::as.vega()
vPlot