Title: | D3 JavaScript Scatterplot from R |
---|---|
Description: | Creates 'D3' 'JavaScript' scatterplots from 'R' with interactive features : panning, zooming, tooltips, etc. |
Authors: | Julien Barnier [aut, cre], Kent Russell [aut, ctb], Mike Bostock [aut, cph] (d3.js library, https://d3js.org), Susie Lu [aut, cph] (d3-legend library, https://d3-legend.susielu.com/), Speros Kokenes [aut, cph] (d3-lasso-plugin library, https://github.com/skokenes/D3-Lasso-Plugin), Evan Wang [aut, cph] (d3-labeler plugin, https://github.com/tinker10/D3-Labeler) |
Maintainer: | Julien Barnier <[email protected]> |
License: | GPL (>=3) |
Version: | 1.0.1.9000 |
Built: | 2024-10-29 05:16:34 UTC |
Source: | https://github.com/juba/scatterD3 |
Generates an interactive scatter plot based on d3.js. Interactive features include zooming, panning, text labels moving, tooltips, fading effects in legend. Additional handlers are provided to change label size, point opacity or export the figure as an SVG file via HTML form controls.
scatterD3( x, y, data = NULL, lab = NULL, x_log = FALSE, y_log = FALSE, point_size = 64, labels_size = 10, labels_positions = NULL, point_opacity = 1, opacities = NULL, hover_size = 1, hover_opacity = NULL, fixed = FALSE, col_var = NULL, col_continuous = NULL, colors = NULL, ellipses = FALSE, ellipses_level = 0.95, symbol_var = NULL, symbols = NULL, size_var = NULL, size_range = c(10, 300), sizes = NULL, col_lab = NULL, symbol_lab = NULL, size_lab = NULL, key_var = NULL, type_var = NULL, opacity_var = NULL, unit_circle = FALSE, url_var = NULL, tooltips = TRUE, tooltip_text = NULL, tooltip_position = "bottom right", xlab = NULL, ylab = NULL, html_id = NULL, width = NULL, height = NULL, legend_width = 150, left_margin = 30, xlim = NULL, ylim = NULL, dom_id_reset_zoom = "scatterD3-reset-zoom", dom_id_svg_export = "scatterD3-svg-export", dom_id_lasso_toggle = "scatterD3-lasso-toggle", transitions = FALSE, menu = TRUE, lasso = FALSE, lasso_callback = NULL, click_callback = NULL, init_callback = NULL, zoom_callback = NULL, zoom_on = NULL, zoom_on_level = NULL, disable_wheel = FALSE, lines = data.frame(slope = c(0, Inf), intercept = c(0, 0), stroke_dasharray = c(5, 5)), axes_font_size = "100%", legend_font_size = "100%", caption = NULL )
scatterD3( x, y, data = NULL, lab = NULL, x_log = FALSE, y_log = FALSE, point_size = 64, labels_size = 10, labels_positions = NULL, point_opacity = 1, opacities = NULL, hover_size = 1, hover_opacity = NULL, fixed = FALSE, col_var = NULL, col_continuous = NULL, colors = NULL, ellipses = FALSE, ellipses_level = 0.95, symbol_var = NULL, symbols = NULL, size_var = NULL, size_range = c(10, 300), sizes = NULL, col_lab = NULL, symbol_lab = NULL, size_lab = NULL, key_var = NULL, type_var = NULL, opacity_var = NULL, unit_circle = FALSE, url_var = NULL, tooltips = TRUE, tooltip_text = NULL, tooltip_position = "bottom right", xlab = NULL, ylab = NULL, html_id = NULL, width = NULL, height = NULL, legend_width = 150, left_margin = 30, xlim = NULL, ylim = NULL, dom_id_reset_zoom = "scatterD3-reset-zoom", dom_id_svg_export = "scatterD3-svg-export", dom_id_lasso_toggle = "scatterD3-lasso-toggle", transitions = FALSE, menu = TRUE, lasso = FALSE, lasso_callback = NULL, click_callback = NULL, init_callback = NULL, zoom_callback = NULL, zoom_on = NULL, zoom_on_level = NULL, disable_wheel = FALSE, lines = data.frame(slope = c(0, Inf), intercept = c(0, 0), stroke_dasharray = c(5, 5)), axes_font_size = "100%", legend_font_size = "100%", caption = NULL )
x |
numerical vector of x values, or variable name if data is not NULL |
y |
numerical vector of y values, or variable name if data is not NULL |
data |
default dataset to use for plot. |
lab |
optional character vector of text labels, or variable name if data is not NULL |
x_log |
if TRUE, set x scale as logarithmic |
y_log |
if TRUE, set y scale as logarithmic |
point_size |
points size. Ignored if size_var is not NULL. |
labels_size |
text labels size |
labels_positions |
Either a data frame, as created by the "Export labels positions" menu entry, giving each label x and y position, or the value '"auto"' to use an automatic labeler. |
point_opacity |
points opacity, as an integer (same opacity for all points). |
opacities |
named list or named vector of opacities. Each opacity will be associated by their name within 'opacity_var'. |
hover_size |
factor for changing size when hovering points |
hover_opacity |
points opacity when hovering |
fixed |
force a 1:1 aspect ratio |
col_var |
optional vector for points color mapping, or variable name if data is not NULL |
col_continuous |
specify if the color scale must be continuous. By
default, if |
colors |
vector of custom points colors. Colors must be defined as an
hexadecimal string (eg "#FF0000"). If |
ellipses |
draw confidence ellipses for points or the different color mapping groups |
ellipses_level |
confidence level for ellipses (0.95 by default) |
symbol_var |
optional vector for points symbol mapping, or variable name if data is not NULL |
symbols |
vector of custom points symbols. Symbols must be defined as
character strings with the following possible values : "circle", "cross",
"diamond", "square", "star", "triangle", and "wye". If |
size_var |
optional vector for points size mapping, or variable name if data is not NULL |
size_range |
numeric vector of length 2, giving the minimum and maximum point sizes when mapping with size_var |
sizes |
named list or named vector of sizes. Each size will be associated by their name within 'size_var'. |
col_lab |
color legend title. Set to NA to remove color legend entirely. |
symbol_lab |
symbols legend title. Set to NA to remove symbol legend entirely. |
size_lab |
size legend title. Set to NA to remove size legend entirely. |
key_var |
optional vector of rows ids, or variable name if data is not NULL. This is passed as a key to d3, and is only added in shiny apps where displayed rows are filtered interactively. |
type_var |
optional vector of points type : "point" for a dot (default), "arrow" for an arrow starting from the origin. |
opacity_var |
optional vector of points opacity (values between 0 and 1) |
unit_circle |
set tot TRUE to draw a unit circle |
url_var |
optional vector of URLs to be opened when a point is clicked |
tooltips |
logical value to display tooltips when hovering points |
tooltip_text |
optional character vector of tooltips text |
tooltip_position |
the tooltip position relative to its point. Must a combination of "top" or "bottom" with "left" or "right" (default is "bottom right"). |
xlab |
x axis label |
ylab |
y axis label. |
html_id |
manually specify an HTML id for the svg root node. A random one is generated by default. |
width |
figure width, computed when displayed |
height |
figure height, computed when displayed |
legend_width |
legend area width, in pixels. Set to 0 to disable legend completely. |
left_margin |
margin on the left of the plot, in pixels |
xlim |
numeric vector of length 2, manual x axis limits |
ylim |
numeric vector of length 2, manual y axis limits |
dom_id_reset_zoom |
HTML DOM id of the element to bind the "reset zoom" control to. |
dom_id_svg_export |
HTML DOM id of the element to bind the "svg export" control to. |
dom_id_lasso_toggle |
HTML DOM id of the element to bind the "toggle lasso" control to. |
transitions |
if TRUE, data updates are displayed with smooth transitions, if FALSE the whole chart is redrawn. Only used within shiny apps. |
menu |
wether to display the tools menu (gear icon) |
lasso |
logical value to add https://github.com/skokenes/D3-Lasso-Plugind3-lasso-plugin feature |
lasso_callback |
the body of a JavaScript callback function with the
argument |
click_callback |
the body of a JavaScript callback function whose inputs are html_id, and the index of the clicked element. |
init_callback |
the body of a JavaScript callback function applied to the scatter object at init time. |
zoom_callback |
the body of a JavaScript callback function whose inputs are the new xmin, xmax, ymin and ymax after a zoom action is triggered. |
zoom_on |
coordinates where to center zoom on plot draw or update. |
zoom_on_level |
zoom level on plot draw or update. Ignored if 'zoom_on' is NULL. |
disable_wheel |
if TRUE, disable zooming with mousewheel. |
lines |
a data frame with at least the |
axes_font_size |
font size for axes text (any CSS compatible value) |
legend_font_size |
font size for legend text (any CSS compatible value) |
caption |
caption to be displayed when clicking on the corresponding icon. Either a character string, or a list with title, subtitle and text elements. |
Interactive scatter plots based on htmlwidgets and d3.js
D3.js was created by Michael Bostock. See https://d3js.org/
scatterD3(x = mtcars$wt, y = mtcars$mpg, data=NULL, lab = rownames(mtcars), col_var = mtcars$cyl, symbol_var = mtcars$am, xlab = "Weight", ylab = "Mpg", col_lab = "Cylinders", symbol_lab = "Manual transmission", html_id = NULL)
scatterD3(x = mtcars$wt, y = mtcars$mpg, data=NULL, lab = rownames(mtcars), col_var = mtcars$cyl, symbol_var = mtcars$am, xlab = "Weight", ylab = "Mpg", col_lab = "Cylinders", symbol_lab = "Manual transmission", html_id = NULL)
Output and render functions for using scatterD3 widgets within Shiny applications and interactive Rmd documents.
scatterD3Output(outputId, width = "100%", height = "600px") renderScatterD3(expr, env = parent.frame(), quoted = FALSE)
scatterD3Output(outputId, width = "100%", height = "600px") renderScatterD3(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width , height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a scatterD3 scatter plot. |
env |
The environment in which to evaluate |
quoted |
Is |