Renata Lúcia Magalhães de Oliveira

Read-And-Delete

  1. Edit YAML front matter
  2. Write using R Markdown
  3. Use an empty line followed by three dashes to separate slides!

Slide 2

require(rCharts)
## Loading required package: rCharts
haireye = as.data.frame(HairEyeColor)
n1 <- nPlot(Freq ~ Hair, group = 'Eye', type = 'multiBarChart',
  data = subset(haireye, Sex == 'Male')
)
n1$print('chart1')
## 
## <div id = 'chart1' class = 'rChart nvd3'></div>
## <script type='text/javascript'>
##  $(document).ready(function(){
##       drawchart1()
##     });
##     function drawchart1(){  
##       var opts = {
##  "dom": "chart1",
## "width":      800,
## "height":      400,
## "x": "Hair",
## "y": "Freq",
## "group": "Eye",
## "type": "multiBarChart",
## "id": "chart1" 
## },
##         data = [
##  {
##  "Hair": "Black",
## "Eye": "Brown",
## "Sex": "Male",
## "Freq":             32 
## },
## {
##  "Hair": "Brown",
## "Eye": "Brown",
## "Sex": "Male",
## "Freq":             53 
## },
## {
##  "Hair": "Red",
## "Eye": "Brown",
## "Sex": "Male",
## "Freq":             10 
## },
## {
##  "Hair": "Blond",
## "Eye": "Brown",
## "Sex": "Male",
## "Freq":              3 
## },
## {
##  "Hair": "Black",
## "Eye": "Blue",
## "Sex": "Male",
## "Freq":             11 
## },
## {
##  "Hair": "Brown",
## "Eye": "Blue",
## "Sex": "Male",
## "Freq":             50 
## },
## {
##  "Hair": "Red",
## "Eye": "Blue",
## "Sex": "Male",
## "Freq":             10 
## },
## {
##  "Hair": "Blond",
## "Eye": "Blue",
## "Sex": "Male",
## "Freq":             30 
## },
## {
##  "Hair": "Black",
## "Eye": "Hazel",
## "Sex": "Male",
## "Freq":             10 
## },
## {
##  "Hair": "Brown",
## "Eye": "Hazel",
## "Sex": "Male",
## "Freq":             25 
## },
## {
##  "Hair": "Red",
## "Eye": "Hazel",
## "Sex": "Male",
## "Freq":              7 
## },
## {
##  "Hair": "Blond",
## "Eye": "Hazel",
## "Sex": "Male",
## "Freq":              5 
## },
## {
##  "Hair": "Black",
## "Eye": "Green",
## "Sex": "Male",
## "Freq":              3 
## },
## {
##  "Hair": "Brown",
## "Eye": "Green",
## "Sex": "Male",
## "Freq":             15 
## },
## {
##  "Hair": "Red",
## "Eye": "Green",
## "Sex": "Male",
## "Freq":              7 
## },
## {
##  "Hair": "Blond",
## "Eye": "Green",
## "Sex": "Male",
## "Freq":              8 
## } 
## ]
##   
##       if(!(opts.type==="pieChart" || opts.type==="sparklinePlus" || opts.type==="bulletChart")) {
##         var data = d3.nest()
##           .key(function(d){
##             //return opts.group === undefined ? 'main' : d[opts.group]
##             //instead of main would think a better default is opts.x
##             return opts.group === undefined ? opts.y : d[opts.group];
##           })
##           .entries(data);
##       }
##       
##       if (opts.disabled != undefined){
##         data.map(function(d, i){
##           d.disabled = opts.disabled[i]
##         })
##       }
##       
##       nv.addGraph(function() {
##         var chart = nv.models[opts.type]()
##           .width(opts.width)
##           .height(opts.height)
##           
##         if (opts.type != "bulletChart"){
##           chart
##             .x(function(d) { return d[opts.x] })
##             .y(function(d) { return d[opts.y] })
##         }
##           
##          
##         
##           
##         
## 
##         
##         
##         
##       
##        d3.select("#" + opts.id)
##         .append('svg')
##         .datum(data)
##         .transition().duration(500)
##         .call(chart);
## 
##        nv.utils.windowResize(chart.update);
##        return chart;
##       });
##     };
## </script>

with option echo = F, results = ‘asis’ you will embed the following rChart on the slides:

Interactive console

## Interactive Console
require(googleVis)
## Loading required package: googleVis
## Creating a generic function for 'toJSON' from package 'jsonlite' in package 'googleVis'
## 
## Welcome to googleVis version 0.6.4
## 
## Please read Google's Terms of Use
## before you start using the package:
## https://developers.google.com/terms/
## 
## Note, the plot method of googleVis will by default use
## the standard browser to display its output.
## 
## See the googleVis package vignettes for more details,
## or visit https://github.com/mages/googleVis.
## 
## To suppress this message use:
## suppressPackageStartupMessages(library(googleVis))
M1 <- gvisMotionChart(Fruits, idvar = 'Fruit', timevar = 'Year')
print(M1, tag = 'chart')