rNVD3
is an R package that provides a familiar plotting interface to create interactive visualizations using NVD3.js
You can install rNVD3
from github
using the devtools
package
require(devtools) install_github('rNVD3', 'ramnathv')
Here is an example that you can try in your R console
hair_eye = subset(as.data.frame(HairEyeColor), Sex == "Female") p1 <- nvd3Plot(Freq ~ Hair | Eye, data = hair_eye, type = 'multiBarChart') p1$chart(color = c('brown', 'blue', '#594c26', 'green')) p1 p1$save('haireye.html')
opts_template$set(nvd3 = list(comment = NA, results = 'asis', message = F, warning = F, tidy = F, echo = T)) require(rNVD3)
bar1 <- nvd3Plot(~ gear, data = mtcars, type = 'discreteBarChart') bar1$printChart()
*** =code
data('tips', package = 'reshape2') bar2 <- nvd3Plot(~ day | sex, data = tips, type = 'multiBarChart') bar2$printChart('barChart')
bar2$addParams(type = 'multiBarHorizontalChart') bar2$printChart('horizontalBar')
p1 <- nvd3Plot(mpg ~ wt | cyl, data = mtcars, type = 'scatterChart') p1$xAxis(axisLabel = 'Weight') p1$printChart()
data(economics, package = 'ggplot2') ecm <- reshape2::melt(economics[,c('date', 'uempmed', 'psavert')], id = 'date') p2 <- nvd3Plot(value ~ date | variable, data = ecm, type = 'lineChart') p2$printChart('lineChart')
p2$addParams(type = 'lineWithFocusChart') p2$printChart('lineWithFocus')
p2$addParams(type = 'cumulativeLineChart') p2$printChart('cumulativeLineChart')
p2$addParams(type = 'stackedAreaChart', id = 'stackedArea') p2$printChart('stackedArea')
haireye <- subset(as.data.frame(HairEyeColor), Sex == "Female" & Hair == "Blond") pie1 <- nvd3Plot(Freq ~ Eye, data = haireye, type = 'pieChart') pie1$printChart()
pie1$chart(donut = TRUE) pie1$printChart('donutChart')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.