Embedding rCharts

Ramnath Vaidyanathan
24-Dec-2013

Outline

This is a short demo on how to embed visualizations created using rCharts in an RStudio Presentation (called RPres).

Make sure to set the chunk options results = "asis" and comment = NA so that the html output is rendered asis by knitr. Set cache = F on this setup chunk to ensure that this chunk is always evaluated.

require(knitr)
opts_chunk$set(results = "asis", comment = NA, tidy = F)

Highcharts

library(rCharts)
h1 <- hPlot(Pulse ~ Height, data = MASS::survey, 
  type = "scatter", group = "Exer"
)

Option 1: IFrame (Inline)

h1$show('iframesrc', cdn = TRUE)

NVD3

hair_eye = as.data.frame(HairEyeColor)
p3 <- nPlot(Freq ~ Hair, group = 'Eye',
  data = subset(hair_eye, Sex == "Female"), 
  type = 'multiBarChart'
)
p3$chart(color = c('brown', 'blue', '#594c26', 'green'))

IFrame Inline

p3$show('iframesrc', cdn = TRUE)

Inline

p3$show('inline', include_assets = TRUE, cdn = TRUE)

BlackBrownRedBlond0.010.020.030.040.050.060.00.066.0BrownBlueHazelGreenGroupedStacked