Ramnath Vaidyanathan
24-Dec-2013
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)
library(rCharts)
h1 <- hPlot(Pulse ~ Height, data = MASS::survey,
type = "scatter", group = "Exer"
)
h1$show('iframesrc', cdn = TRUE)
h1$show('inline', include_assets = TRUE, cdn = TRUE)
hair_eye = as.data.frame(HairEyeColor)
p2 <- rPlot(Freq ~ Hair, color = 'Eye',
data = hair_eye,
type = 'bar'
)
p2$facet(var = 'Eye', type = 'wrap', rows = 2)
p2$show('iframesrc', cdn = TRUE)
# NOTE HOW CSS INTERFERES WITH CHART
p2$show('inline', include_assets = TRUE, cdn = TRUE)
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'))
p3$show('iframesrc', cdn = TRUE)
p3$show('inline', include_assets = TRUE, cdn = TRUE)