--- name: DynamicVisualizations topic: Dynamic Visualizations and Interactive Graphics maintainer: Sherry Zhang, Dianne Cook, Ian Lyttle email: huizezhangsh@gmail.com version: 2024-09-25 source: https://github.com/cran-task-views/DynamicVisualizations/ --- Dynamic visualizations include interactive graphics which offer the flexibility for users to interact with the plot, with mouse or cursor selection, for example. This can be useful to query additional details, such as using mouse-over to provide additional information about a point or line in the plot. For exploratory data analysis, it is beneficial to view and link multiple plots using highlighting or brushing. Most interactivity is provided by interfacing R with external libraries like JavaScript (JS). Dynamic visualizations also include animations which are generated by rendering successive frames in the plot window. This CRAN task view maintains a list of the dynamic graphics packages, for making animations and interactive plots. Static plots are not within the scope of this CRAN task view, neither are graphics devices. Some packages that include only one or two functions to produce interactive plots or animations but are mostly focused on modeling methods or applications are typically not included. If you think that a package is missing from this list, you can post an issue or directly add using a pull request in the [GitHub repository](https://github.com/cran-task-views/DynamicVisualizations). Alternatively, you can contact the maintainer via e-mail. The listed packages are grouped into general-purpose packages and those designed for specific applications: multivariate, temporal, maps, networks, and miscellaneous packages for specific plot types. ## General purpose The `r pkg("crosstalk", priority = "core")` package enables linked brushing across interactive plots created from `htmlwidgets`, rather than creating interactive plots itself. Linked brushing is an interactive action useful for viewing the data from multiple visualizations to identify clusters, outliers, or other structure in the data. Compatible widgets with the crosstalk framework include `plotly` and `leaflet`. The `r pkg("r2d3")` package binds raw [D3.js](https://d3js.org/) codes to R data objects, allowing D3 code to run with R-native data objects. This approach offers full customization of interactive details using JS but requires writing JS code. Packages built on the `r2d3` framework: `r pkg("ddplot")` creates animated histogram and line chart upon clicking, among other plot types. The following packages can all create interactive graphics of basic types, including scatterplots, bar charts, histograms etc. Most packages offer support to highlight plot elements (dots, bars, lines, etc.) and display tooltips upon hovering. This review covers the syntax for plotting, as well as the interactive actions and plot types supported. - The `r pkg("plotly", priority = "core")` package (*plotly.js*) creates the graphics from the native plotly syntax: initialize with `plot_ly()`, specify shapes (markers, lines, etc.) through `add_*()`, control axes and legends with `layout()`, and color with `colorbar()`. Variables are specified with a `~` upfront. Every `plotly` plot includes a toolbar that allows panning and zooming, box/lasso selection, saving and supports brushed linking across multiple data plots. It also supports click on categorical legend to show/hide categories. The `plotly` package also supports converting ggplot2 objects directly into interactive plots via the `ggplotly()` function. Animation through `plotly` is introduced under the *Animation* section. See Carson Sievert's book [Interactive web-based data visualization with R, plotly, and shiny](https://plotly-r.com/) for more details. - The `r pkg("ggiraph", priority = "core")` package is an extension to `ggplot2` for interactive graphics by providing interactive versions of the `geom`, `scale`, `facet`, `guide`, and `theme` functions/elements. The interactivity allows for customized tooltips with JS code, as well as hover and click effects. - In `r pkg("echarts4r")` (*echarts.js*), a plot is initialized by `e_charts()` and different plot elements (shapes, axes, theme, etc.) are built with the `e_*` functions, e.g. `e_line()`, `e_axis_labels()`, `e_theme()`. It covers most basic chart types, statistical graphics (confidence band, correlation matrix, etc.), geospatial maps, some timeline (time series) displays, and network diagrams. WebGL render is also supported, as well as using customized icons/pictures in the plot. A unique interactive action supported by the package is to drag the end of the color/fill legend to filter the data within the range on the plot (see `e_visual_map()`). - In `r pkg("highcharter")` (*highcharts.js*), a plot is initialized by `hchart()` or built with `hc_add_series()`. Plot elements (legend, color, axis, etc.) are adjusted using the `hc_*()` functions. The package supports visualizing maps, network diagrams, and statistical plots (e.g., PCA plot after `princomp()`, correlation matrix). For temporal plots, it supports linked tracking across multiple series and zooming at various scales, through button clicking or dragging on the subchart. It also supports clicking to view the treemap at different hierarchical levels. - In `r pkg("billboarder")` (*billboard.js* ), a plot is initialized by `billboarder()` and plot elements (shape, axes, legend, etc.) are specified through `bb_*()` functions. Zooming on time series plots is supported by selecting the main plot (`bb_zoom()`) or a subchart (`bb_subchart()`). - `r pkg("googleVis")` (*Google Charts*) uses the syntax, `gvis[ChartType]()`, rather than a grammar to specify the plot, e.g., `gvisScatterChart()`. Additional controls of plot elements are passed as a list of `options` inside the main function. It supports creating maps, interactive tables, treemaps, network and Sankey diagrams, and calendar plots. - `r pkg("rAmCharts")` and `r pkg("rAmCharts4")` (*amcharts.js*) uses the syntax `amChartType()` to specify the plot. It supports the selection of multiple datasets through the selection box, see `amStockMultiSet()`. - `r pkg("ggvis")` follows the grammar of graphics in `ggplot2` to express interactive graphics for general purpose exploratory data analysis. Notice that although the package is currently listed on CRAN, it is labelled as dormant by its developers on GitHub. - `r pkg("RJSplot")` allows easy the generation of interactive graphics. RJSplot includes eleven graphs, such as a genome browser, Manhattan plot, genome map, network browser, heatmap, scatter plot, etc. Some live examples and tutorials can be seen on the project Web site: [https://rjsplot.usal.es](https://rjsplot.usal.es). ## Animation - The `r pkg("gganimate", priority = "core")` package extends the grammar of graphics in `ggplot2` to describe animations. It provides functions to specify transition between frames (`transition_*()`), appearance and disappearance of data (`enter_*()/ exit_*()`), among others. - The `r pkg("plotly", priority = "core")` package supports animation through specifying a `frame` (and `ids`) aesthetic in the graphical element (markers, lines, etc.). - The `r pkg("animate")` package supports creating animations using base R syntax and is powered by D3.js. - The `r pkg("animation")` package provides a gallery of animated illustrations of common statistical concepts, such as bootstrapping and the Central Limit Tehorem (CLT), designed for teaching purposes. ## Multivariate One of the most common visualizations for high dimension data is scatterplot matrix. - It can be created with `GGally::ggpairs()` and turned into interactive using `plotly::ggplotly()` to enable linked brushing to view the data at different variable combinations. - The `r pkg("pairsD3")` package creates scatterplot matrices through D3.js. When the multivariate relationship is attributed to more than two variables, a scatterplot matrix becomes insufficient and a family of techniques, called tour, can be useful to explore the structure in high dimensional data. The tour technique animates a sequence of linear projections of high dimensional data and it has two components: (1) tour type: how the projection sequence is generated, and (2) display: how low-D projections are displayed. Different tours are available to select the projection sequences (grand tour: random selection, guided tour: based on projection pursuit, etc.). The most common display is histograms for 1D projections and scatterplots for 2D projections. Other higher-D displays are also available, including Chernoff faces. - `r pkg("tourr")` implements varies tourr types (`grand_tour`, `guided_tour`, `planned_tour`, `local_tour`, etc.) and displays (`animate_xy`: 2D, `animate_dist`: 1D, etc.) to create frame-by-frame animation. - `r pkg("spinifex")` implements the manual tourr algorithm (`manual_tour`). - `r pkg("liminal")` implements linked display view to understanding embedding algorithms such as tSNE through `r pkg("vegawidget")`. - `r pkg("detourr")` implements the 2D and 3D scatterplot display with three.js for better interactive manipulations (rotation, pan, selection, brushing with color and time control). - `r pkg("langevitour")` implements the Langevin dynamics to generate projection sequence and builds the display with D3.js. - `r pkg("woylier")` implements the Given interpolation method to generate projection sequences for rotation variant projection pursuit indexes (those index values change when rotating the projection within the plane), e.g., the spline index. - `r pkg("ferrn")` provides diagnostic plots (track index values and visualize the basis space) to the optimization routine of the projection pursuit guided tour. Another class of interactive visualization in R is the `r pkg("loon")` toolkit. The graphic system is written in Tcl and accessed in R via the `tcltk` package. The `r pkg("parallelPlot")` package (*D3.js*) creates parallel coordinate plots (PCP) and scatterplot matrices with linked brushing to hightlight points and ranges on the PCP axis. ## Temporal - The `r pkg("tsibbletalk")` package creates shared `tsibble` objects to generate linked plots of time series and other plots within the `r pkg("crosstalk", priority = "core")` framework. - The `r pkg("dygraphs")` package (*dygraphs.js*) creates interactive time series plots for `xts` objects and supports interactive features including series highlights, value tracking, annotating event and confidence interval, range selection, and rolling window smoothing. - The `r pkg("timevis")` package (*vis.js*) creates timeline visualization for project management and event scheduling. It supports dragging and zooming on the time axis and is compatible with `crosstalk` for linked brushing. ## Maps ### General purpose packages - The `r pkg("plotly")` package provides functionality for general-purpose interactive maps that fit into the `plotly` ecosystem, supporting features like linked brushing. Simple, quick basemaps can be created with the `plot_mapbox()` and `plot_geo()` constructor. For more complex, data-driven maps (e.g., with `sf`), use the `plot_ly()` constructor or `ggplotly()` on a `ggplot2` object. - The `r pkg("ggiraph")` package supports converting `ggplot2` objects into interactive graphs. It allows flexible customization options for interactivity, including tooltip text, onclick effects, CSS for hover and select, allowing additional information to be incorporated into the visualization (e.g., linking to an external website upon clicking). - The `r pkg("highcharter")` package supports maps created from data frames/tibbles and the `geo_json` class from the `geojsonio` package. It allows customization of tooltips and enables legend clicking to show or hide categories. ### Specialized map packages #### The leaflet family The `r pkg("leaflet", priority = "core")` package is one of the most popular JS libraries for interactive maps. It supports creating maps for a wide range of R objects, including data frames, sf, GeoJSON/TopoJSON, raster images from the `terra` or `raster` packages. The package allows flexible customization of display and interactive options: enhencing tooltips and labels with CSS, changing basemap styles and showing/hiding layers through clicking the legend, customized marker icons via URL links and Font Awesome, a variety of basemap options, (including Open Street Map, Stamen, Stadia, ESRI, and customized map tiles), distance and area calculation from clicking points on the map (with `addMeasure()`), a mini global map for zooming, just to name a few. Leaflet maps can cross-talk with other interactive visualizations through the `r pkg("crosstalk")` package. The ecosystem is further enhanced through plugins: - `r pkg("leafpop")` displays static plots in the tooltip popups. - `r pkg("leafsync")` displays multiple synced leaflet maps in small multiples. - `r pkg("leaflet.minicharts")` displays glyphs (pie and bar), with animation, on the map. - `r pkg("leaflegend")` adds customized images as marks and in the legend. - `r pkg("leafem")` supports GIS-related layers, (e.g., Cloud Optimized Geotiff (COG), stars/rasters images). - `r pkg("leafgl")` renders large scale data (e.g., 1 million points or 100k polygons) with the WebGL framework. #### Others - The `r pkg("tmap")` package provides a ggplot2-styled grammar of graphic for thematic maps (both static and interactive) and uses leaflet to render interactive maps. - The `r pkg("mapview")` package creates quick leaflet and mapdeck maps with short syntax from common spatial classes in R such as `sf`, `raster`, and `stars`. - The `r pkg("mapboxer")` package interfaces with Mapbox GL JS to create interactive maps. It leverages resources from the JS library for basemap styles, aesthetics controls, interactive controls, including interactive filtering ("expressions") and point clustering. - The `r pkg("deckgl")` package interfaces with deck.gl for interactive maps. It offers an interactive editor to fine tune the map (`add_json_editor()`). - The `r pkg("mapdeck")` package interactive visualization for large data sets via Mapbox GL and deck.gl. It supports a wider set of objects including data frame, sf (sfencoded, sfencodedLite), geojson/json/GeoJSON. - The `r pkg("evolMap")` package provides interactive and temporal maps with a GUI which enable the exploration of information and customization of visual aspects. Represents and manages information from a database on an interactive geographic map. It also allows to view the evolution of the added elements over time or in periods. Tutorials can be seen on the developer Github: [https://github.com/BioinfoUSAL/VisualAnalyticsWorkshop](https://github.com/BioinfoUSAL/VisualAnalyticsWorkshop). ## Networks Packages are available for plotting simple networks: - The `r pkg("sigmajs")` package has its own grammar for constructing network diagrams. It supports data structure from `igraph` and `gexf` and can use various `igraph` layouts to display the network. The package has also implemented plugins from the `sigma.js`, which includes highlight neighbor nodes and apply customized images for nodes. - The `r pkg("networkD3")` package (*D3.js*) produces simple/force network, Sankey diagram, dendrogram. The visualization can be created from `igraph` objects. - The `r pkg("visNetwork")` package (*vis.js*) creates network diagrams through node and edge data frames. It supports visualizing classification tree results from the `rpart` package. - The `r pkg("collapsibleTree")` package creates collapsible tree diagram to visualize hierarchical data structures based on D3.js. It supports clicking on tree nodes to expand and collapse child nodes, as well as tooltips and zooming. - The `r pkg("rD3plot")` package creates interactive, temporal networks with a GUI which enable the exploration of information and customization of visual aspects. Represents and manages information from a database about a network. It also allows you to view the evolution of the added elements. It provides node search, filter, display customization, playback controls and bar charts. Information can be explored on a table, tool tips and information window. Tutorials can be seen on the developer Github: [https://github.com/BioinfoUSAL/VisualAnalyticsWorkshop](https://github.com/BioinfoUSAL/VisualAnalyticsWorkshop). ## Miscellaneous R also includes packages dedicated to specific interactive visualizations, often by interfacing with relevant JS libraries. - The `r pkg("trelliscopejs")` package (*trelliscope.js*) enables the interactive visualization of small multiples, making it particularly suitable for visualizing large collections of multiples that cannot be displayed on a single screen through facets. The package offers `facet_trelliscope()`, as a drop-in replacement for `facet_wrap()`/`facet_grid()`, as well as `trelliscope()`, a more general function that fits into the tidy workflow where data transformation (compute summaries, models, etc.) can be handled by nested data and list-column. - The `r pkg("heatmaply")` package (*plotly.js*) allows interactive heatmaps with actions like cell-hover tooltips and zooming into specific areas. It supports data transformations such as scaling, normalizing, and percentizing, and the dendrograms for viewing the structure of observations can be customized using the `dendextend` package. - The `r pkg("iheatmapr")` package (*plotly.js*) supports heatmaps with more complex subplots in addition to clustering dendrograms. It includes annotations for group categories and customizable plots for row and column summary statistics. It also supports displaying multiple heatmaps side-by-side. - The `tcltk` package (part of base packages) provides access to the platform-independent Tcl scripting language and Tk GUI elements, forming the basis for other packages. - The `r pkg("rgl")` package provides 3D visualizations built with OpenGL or WebGL as the rendering backend. ### Links - Book: [Interactive web-based data visualization with R, plotly, and shiny](https://plotly-r.com) - Book: [JavaScript for R](https://book.javascript-for-r.com/) - Book: [Interactively exploring high-dimensional data and models in R](https://dicook.github.io/mulgar_book/)