D3 JavaScript Scatterplot from R

Creates 'D3' 'JavaScript' scatterplots from 'R' with interactive features : panning, zooming, tooltips, etc.


scatterD3 is an HTML R widget for interactive scatter plots visualization. It is based on the htmlwidgets R package and on the d3.js javascript library.

Here is a small preview of what you will get :

Take a look at the visual guide for a list of features and examples. You can also test it live with the sample shiny app.

Install latest stable release from CRAN :

install.packages("scatterD3")

Or from Github for the latest, bleeding edge, full of bugs version :

devtools::install_github("juba/scatterD3")

Quick example of the scatterD3 function based on the mtcars dataset :

mtcars$names <- rownames(mtcars)
scatterD3(data = mtcars, x = wt, y = mpg, lab = names,
          col_var = cyl, symbol_var = am,
          xlab = "Weight", ylab = "Mpg", col_lab = "Cylinders",
          symbol_lab = "Manual transmission")

See the visual guide for a step-by-step guide and details about the different function arguments.

Like every R HTML widget, shiny integration is straightforward. But as a D3 widget, scatterD3 is updatable : changes in settings or data can be displayed via smooth transitions instead of a complete chart redraw, which can provide interesting visual clues.

Furthermore, scatterD3 provides some additional handlers and callback hooks for a more complete JavaScript interactivity and integration.

The sample scatterD3 shiny app allows you to see the different features described here. You can check its source code on GitHub and the visual guide for a better understanding of the different arguments.

This package has been made possible by :

News

  • Bugfix : categorical axes labels shown as NaN (thanks @zji90)
  • Bugfix : plot not centered when fixed = TRUE (thanks @jon-nagra)
  • Bugfix : incorrect plot when only one point (thanks @CUinNYC)
  • Bugfix : xlim and ylim not taken into account when updating chart (thanks @CUinNYC)
  • Bugfix : plot with no data should return an empty plot, not an error
  • Bugfix : tick marks must be put below axes labels
  • New "caption" argument to add a toggable caption to the plot
  • New "x_log" and "y_log" arguments for x and y logarithmic scales
  • New argument labels_positions, allows to import a previously saved labels positions file
  • Toggle "export labels position" visibility when labels change
  • Bugfix : incoherent data on mouseover after data updating
  • Bugfix : unable to export SVG when text contains non-Latin1 characters
  • Upgrade to d3v4
  • Add data argument to specify variables from a data frame with NSE
  • New menu accessible directly from the graph to allow zoom resetting, SVG export, etc.
  • Continuous color scales are now supported. They are automatically guessed from col_var characteristics, but can be forced with the col_continuous argument.
  • Categorical variables are now allowed for x and y.
  • New lines argument to add custom lines to the plot
  • New argument : opacity_var to specify points opacity individually with a vector. Use point_opacity to specify a constant opacity.
  • New argument : url_var to specify URLs to be opened when a point is clicked.
  • Add click_callback parameter, opening a hook for a click event listener (thanks @detule and @harveyl888)
  • Add zoom_callback parameter, opening a hook for a zoom event listener
  • New "export labels position" feature
  • New settings hover_size and hover_opacity (thanks @nicolabo)
  • Axes and legend font size customization with axes_font_size and legend_font_size (thanks @fineswag)
  • Better legend transitions when updating
  • JavaScript code split into several subfiles
  • Left margin customization with the left_margin argument
  • More precise font-family specification for (hopefully) better rendering
  • Bugfix : blank plot when only one color passed to colors (thanks @chewth)
  • Darker points color during lasso selection
  • Bugfix : Remove any previous anchor from clip-path urls
  • Bugfix : deal with NA in size_var
  • New feature : d3 lasso plugin integration, initial work by @timelyportfolio
  • New feature : allow to draw confidence ellipses for all points or for col_var groups
  • Bugfix : underscores appearing instead of spaces in legend text (thanks @TimBock)
  • Bugfix : xlim and ylim not taken ignored when fixed = TRUE (thanks @TimBock)
  • Bugfix : legend must not be displayed when legend_width = 0 and fixed = TRUE (thanks @TimBock)
  • Bugfix : wrong legend hover highlighting when the label is "0"
  • Bugfix : convert NA to "NA" in color and symbol mapping variables
  • Fix zoom reset when several charts in the same shiny app
  • Switch to 20 colors ordinary scales if there are more than 10 color variable levels
  • Bugfix : wrong svg reference passed to hover legend functions when several scatterD3 instances in the same shiny app
  • Make point labels updatable
  • Manage changes of unit_circle settings
  • Bugfixes for when several scatterD3 instances are in the same shiny app
  • Fix fixed 1:1 aspect ratio not working as intended
  • New unit_circle argument to draw a unit circle around origin
  • Text labels are placed below the corresponding arrow by default when y < 0
  • New type_var argument, which allows to selectively draw arrows (starting from origin) instead of points
  • A temporary line is drawn between text and point when dragging a label
  • Fix plots updating when several widgets are in the same shiny app
  • Fix tooltips not showing in Firefox
  • Fix clip-path URL problems when exporting to SVG
  • Charts integrated into a shiny app are now fully updatable : when data or settings change, the plot is updated with smooth transitions instead of being redrawn. See the transitions and key_var arguments.
  • HTML DOM id of elements linked to the "Reset zoom" and "Export to SVG" features can now be given as arguments.
  • Add colors argument to specify a custom set of point colors. A named vector can be used to directly map values to colors (Thanks @timelyportfolio)
  • Complete code reorganisation, much cleaner
  • New legend_width argument
  • Use d3-legend plugin for legend generation (http://d3-legend.susielu.com/)
  • New xlim and ylim arguments for manual axis limits specification (Thanks @tinyheero)
  • Fix tooltips not showing under Shiny/Bootstrap (Thanks @tinyheero for reporting)
  • Fix tooltip content when several scatter plots are displayed on the same page
  • Respect custom label position when zooming
  • First version

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("scatterD3")

0.8.1 by Julien Barnier, 9 months ago


https://github.com/juba/scatterD3


Report a bug at https://github.com/juba/scatterD3/issues


Browse source code at https://github.com/cran/scatterD3


Authors: Julien Barnier [aut, cre], Kent Russell [aut, ctb], Mike Bostock [aut, cph] (d3.js library, http://d3js.org), Susie Lu [aut, cph] (d3-legend library, http://d3-legend.susielu.com/), Speros Kokenes [aut, cph] (d3-lasso-plugin library, https://github.com/skokenes/D3-Lasso-Plugin)


Documentation:   PDF Manual  


GPL (>= 3) license


Imports htmlwidgets, digest, ellipse

Suggests knitr, rmarkdown

Enhances shiny


Imported by explor, treespace.


See at CRAN