rNVD3

Interactive Charts from R using NVD3.js

View the Project on GitHub ramnathv/rNVD3

Interactive Charts from R using NVD3

This R package helps users create interactive visualizations with NVD3, using a plotting interface similar to the lattice package.

Installation

You can install rNVD3 from github using the devtools package

require(devtools)
install_github('rNVD3', 'ramnathv')

Usage

rNVD3 uses a plotting interface similar to that of the lattice package. Here are a few examples you can try out in your R console.

Example 1: Discrete Bar Plot

require(rNVD3)
bar1 <- nvd3Plot(~gear, data = mtcars, type = "discreteBarChart", width = 600)
bar1$printChart("chart1")

Example 2: Stacked bar Plot

hair_eye = subset(as.data.frame(HairEyeColor), Sex == "Female")
p1 <- nvd3Plot(Freq ~ Hair | Eye, data = hair_eye, type = 'multiBarChart', width = 600)
p1$chart(color = c('brown', 'blue', '#594c26', 'green'))
p1$printChart('chart2')

rNVD3 is merely a wrapper around nvd3.js. More documentation and examples are underway.

Using with Shiny

rCharts is compatible with Shiny. Here is a link to the rCharts Shiny App.

## server.r
require(rNVD3)
shinyServer(function(input, output) {
  output$myChart <- renderChart({
    hair_eye = as.data.frame(HairEyeColor)
    p6 <- nvd3Plot(Freq ~ Hair | Eye, data = subset(hair_eye, Sex == input$gender), 
      type = input$type, id = 'myChart', width = 800)
    p6$chart(color = c('brown', 'blue', '#594c26', 'green'), stacked = input$stack)
    return(p6)
  })
})

## ui.R
require(rNVD3)
shinyUI(pageWithSidebar(
  headerPanel("rNVD3: Interactive Charts from R using NVD3.js"),

  sidebarPanel(
    selectInput(inputId = "gender",
      label = "Choose Gender",
      choices = c("Male", "Female"),
      selected = "Male"),
    selectInput(inputId = "type",
      label = "Choose Chart Type",
      choices = c("multiBarChart", "multiBarHorizontalChart"),
      selected = "multiBarChart"),
    checkboxInput(inputId = "stack",
      label = strong("Stack Bars?"),
      value = FALSE)
  ),
  mainPanel(
    showOutput("myChart")
  )
))

Credits

Most of the implementation in rNVD3 is inspired by rHighcharts and rVega. I have reused some code from these packages verbatim, and would like to acknowledge the efforts of its author Thomas Reinholdsson.

License

rNVD3 is licensed under the MIT License. NVD3 is licensed under Apache License, Version 2.0. You can read Read more about its license here