.. _nvd3_charttypes: Create ======= .. raw:: html The `NVD3 `_ library supports most of the common chart types. .. contents:: :local: :depth: 1 You can create an interactive plot making use of the NVD3 library using the :func:`nPlot` function. .. list-table:: :widths: 25 25 70 :header-rows: 1 * - Argument - Type - Description * - x - formula - A formula of the form y \~ x, with column names from the data frame. * - data - data frame - A data frame containing the data to be plotted * - type - string - The type of chart to plot * - group - string - Name of column based on which data should be grouped. Scatter Chart -------------- .. sourcecode:: r p1 <- nPlot(mpg ~ wt, group = 'cyl', data = mtcars, type = 'scatterChart') p1$xAxis(axisLabel = 'Weight') p1 .. only:: html .. raw:: html .. raw:: html Edit
:download:`Standalone <_downloads/nvd3-scatter.html>` Multibar Chart -------------- .. sourcecode:: r hair_eye = as.data.frame(HairEyeColor) p2 <- nPlot(Freq ~ Hair, group = 'Eye', data = subset(hair_eye, Sex == "Female"), type = 'multiBarChart' ) p2$chart(color = c('brown', 'blue', '#594c26', 'green')) p2 .. only:: html .. raw:: html .. raw:: html Edit
:download:`Standalone <_downloads/nvd3-multibar.html>` Multibar Horizontal Chart ------------------------- .. only:: html .. raw:: html .. raw:: html Edit
:download:`Standalone <_downloads/nvd3-multibar-horizontal.html>` Pie Chart ---------- .. sourcecode:: r p4 <- nPlot(~ cyl, data = mtcars, type = 'pieChart') p4 .. only:: html .. raw:: html .. raw:: html Edit
:download:`Standalone <_downloads/nvd3-pie.html>` Donut Chart ------------ .. sourcecode:: r p5 <- nPlot(~ cyl, data = mtcars, type = 'pieChart') p5$chart(donut = TRUE) p5 .. only:: html .. raw:: html .. raw:: html Edit
:download:`Standalone <_downloads/nvd3-donut.html>` Line Chart ----------- .. sourcecode:: r data(economics, package = 'ggplot2') p6 <- nPlot(uempmed ~ date, data = economics, type = 'lineChart') p6 .. only:: html .. raw:: html .. raw:: html Edit
:download:`Standalone <_downloads/nvd3-line.html>` Line with Focus Chart --------------------- .. sourcecode:: r ecm <- reshape2::melt( economics[,c('date', 'uempmed', 'psavert')], id = 'date' ) p7 <- nPlot(value ~ date, group = 'variable', data = ecm, type = 'lineWithFocusChart' ) p7 .. only:: html .. raw:: html .. raw:: html Edit
:download:`Standalone <_downloads/nvd3-line-with-focus.html>` Stacked Area Chart ------------------- .. sourcecode:: r dat <- data.frame( t = rep(0:23, each = 4), var = rep(LETTERS[1:4], 4), val = round(runif(4*24,0,50)) ) p8 <- nPlot(val ~ t, group = 'var', data = dat, type = 'stackedAreaChart', id = 'chart' ) p8 .. only:: html .. raw:: html .. raw:: html Edit
:download:`Standalone <_downloads/nvd3-stacked-area.html>` Multi Chart ----------- .. sourcecode:: r p12 <- nPlot(value ~ date, group = 'variable', data = ecm, type = 'multiChart') p12$set(multi = list( uempmed = list(type="area", yAxis=1), psavert = list(type="line", yAxis=2) )) p12$setTemplate(script = system.file( "/libraries/nvd3/layouts/multiChart.html", package = "rCharts" )) p12 .. only:: html .. raw:: html .. raw:: html Edit
:download:`Standalone <_downloads/nvd3-multi-chart.html>` .. raw:: html