rNVD3

Interactive Charts from R using NVD3.js

Ramnath Vaidyanathan

Download

Introduction

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')

Bar Chart (Discrete)

bar1 <- nvd3Plot(~ gear, data = mtcars, type = 'discreteBarChart')
bar1$printChart()

Bar Chart (Dodged/Stacked)

data('tips', package = 'reshape2')
bar2 <- nvd3Plot(~ day | sex, data = tips, type = 'multiBarChart')
bar2$printChart('barChart')

Bar Chart (Horizontal)

bar2$addParams(type = 'multiBarHorizontalChart')
bar2$printChart('horizontalBar')

Scatter Chart

p1 <- nvd3Plot(mpg ~ wt | cyl, data = mtcars, type = 'scatterChart')
p1$xAxis(axisLabel = 'Weight')
p1$printChart()

Line Chart

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')

Line with Focus Chart

p2$addParams(type = 'lineWithFocusChart')
p2$printChart('lineWithFocus')

Cumulative Line Chart

p2$addParams(type = 'cumulativeLineChart')
p2$printChart('cumulativeLineChart')

Stacked Area Chart

p2$addParams(type = 'stackedAreaChart', id = 'stackedArea')
p2$printChart('stackedArea')

Pie Chart

haireye <- subset(as.data.frame(HairEyeColor), Sex == "Female" & Hair == "Blond")
pie1 <- nvd3Plot(Freq ~ Eye, data = haireye, type = 'pieChart')
pie1$printChart()

Donut Chart

pie1$chart(donut = TRUE)
pie1$printChart('donutChart')