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 :
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 :
symbols
argument and custom symbol to value mapping (thanks @GiuseppeDiGuglielmo and @mmauri)tooltip_position
argument to define tooltip placement (thanks @Tixierae)disable_wheel
argument to disable mousewheel zooming (thanks @romanhaa)colors
argument for continuous color variables (thanks @romanhaa)zoom_on
and zoom_on_level
arguments for programmatic zooming (thanks @Tixierae)labels_positions = "auto"
labels_positions
, allows to import a previously saved labels positions filedata
argument to specify variables from a data frame with NSEcol_var
characteristics, but can be forced with the col_continuous
argument.x
and y
.lines
argument to add custom lines to the plotopacity_var
to specify points opacity individually with a vector. Use point_opacity
to specify a constant opacity.url_var
to specify URLs to be opened when a point is clicked.click_callback
parameter, opening a hook for a click event listener (thanks @detule and @harveyl888)zoom_callback
parameter, opening a hook for a zoom event listenerhover_size
and hover_opacity
(thanks @nicolabo)axes_font_size
and legend_font_size
(thanks @fineswag)left_margin
argumentcolors
(thanks @chewth)fixed
1:1 aspect ratio not working as intendedunit_circle
argument to draw a unit circle around origintype_var
argument, which allows to selectively draw arrows (starting from origin) instead of pointstransitions
and key_var
arguments.colors
argument to specify a custom set of point colors. A named vector can be used to directly map values to colors (Thanks @timelyportfolio)legend_width
argumentd3-legend
plugin for legend generation (http://d3-legend.susielu.com/)xlim
and ylim
arguments for manual axis limits specification (Thanks @tinyheero)