Title: | 'Htmlwidget' for 'd3.js' Parallel Coordinates Chart |
---|---|
Description: | Create interactive parallel coordinates charts with this 'htmlwidget' wrapper for 'd3.js' <https://github.com/BigFatDog/parcoords-es> {'parallel-coordinates'}. |
Authors: | Mike Bostock [aut, cph] (d3.js library in htmlwidgets/lib, http://d3js.org), Kai Chang [aut, cph] (parallel coordinates reusable chart, https://github.com/syntagmatic/parallel-coordinates), Xing Yun [aut, cph] ('es6' parallel coordinates, https://github.com/BigFatDog/parcoords-es), Kenton Russell [aut, cre] (R interface), Anobel Odisho [aut] (R interface guidance, suggestions, testing, review, and feedback), Mark Albrecht [ctb] (Shiny output and example) |
Maintainer: | Kenton Russell <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.1 |
Built: | 2024-11-23 02:47:04 UTC |
Source: | https://github.com/timelyportfolio/parcoords |
Create interactive parallel coordinates charts with this htmlwidget wrapper for d3.js parallel-coordinates.
parcoords(data = NULL, rownames = TRUE, color = NULL, brushMode = NULL, brushPredicate = "and", alphaOnBrushed = NULL, reorderable = FALSE, axisDots = NULL, margin = NULL, composite = NULL, alpha = NULL, queue = FALSE, mode = FALSE, rate = NULL, dimensions = NULL, bundleDimension = NULL, bundlingStrength = 0.5, smoothness = 0, tasks = NULL, autoresize = FALSE, withD3 = FALSE, width = NULL, height = NULL, elementId = NULL)
parcoords(data = NULL, rownames = TRUE, color = NULL, brushMode = NULL, brushPredicate = "and", alphaOnBrushed = NULL, reorderable = FALSE, axisDots = NULL, margin = NULL, composite = NULL, alpha = NULL, queue = FALSE, mode = FALSE, rate = NULL, dimensions = NULL, bundleDimension = NULL, bundlingStrength = 0.5, smoothness = 0, tasks = NULL, autoresize = FALSE, withD3 = FALSE, width = NULL, height = NULL, elementId = NULL)
data |
data.frame with data to use in the chart |
rownames |
logical use rownames from the data.frame in the chart. Regardless of
this parameter, we will append rownames to the data that we send to JavaScript.
If |
color |
Color can be a single color as rgb or hex. For a color function,
provide a
|
brushMode |
string, either |
brushPredicate |
string, either |
alphaOnBrushed |
opacity from 0 to 1 when brushed (default to 0). |
reorderable |
logical enable reordering of axes |
axisDots |
logical mark the points where polylines meet an axis with dots |
margin |
list of sizes of margins in pixels. Currently
|
composite |
foreground context's composite type |
alpha |
opacity from 0 to 1 of the polylines |
queue |
logical (default FALSE) to change rendering mode to queue for
progressive rendering. Usually |
mode |
string see |
rate |
integer rate at which render will queue |
dimensions |
|
bundleDimension |
character string for the column or variable on which to bundle |
bundlingStrength |
numeric value between 0 and 1 for the strength of the bundling. This value will
not affect the parallel coordinates if |
smoothness |
numeric value between between 0 and 1 for stength of smoothing or curvature. This value will
not affect the parallel coordinates if |
tasks |
a character string or |
autoresize |
logical (default FALSE) to auto resize the parcoords when the size of the container changes. This is useful in contexts such as rmarkdown slide presentations or flexdashboard. However, this will not be useful if you expect bigger data or a more typical html context. |
withD3 |
|
width |
integer in pixels defining the width of the widget. Autosizing to 100
of the widget container will occur if |
height |
integer in pixels defining the height of the widget. Autosizing to 400px
of the widget container will occur if |
elementId |
unique |
An object of class htmlwidget
that will
intelligently print itself into HTML in a variety of contexts
including the R console, within R Markdown documents,
and within Shiny output bindings.
if(interactive()) { # simple example using the mtcars dataset data( mtcars ) parcoords( mtcars ) # various ways to change color # in these all lines are the specified color parcoords( mtcars, color = "green" ) parcoords( mtcars, color = "#f0c" ) # in these we supply a function for our color parcoords( mtcars , color = list( colorBy = "cyl" , colorScale = "scaleOrdinal" , colorScheme = "schemeCategory10" ) , withD3 = TRUE ) if(require('ggplot2', quietly = TRUE)) { parcoords( diamonds ,rownames = FALSE ,brushMode = "1d-axes" ,reorderable = TRUE ,queue = TRUE ,color= list( colorBy="cut" , colorScale = "scaleOrdinal" , colorScheme = "schemeCategory10" ) ,withD3 = TRUE ) } } library(parcoords) parcoords( mtcars, dimensions = list( cyl = list( title = "cylinder", tickValues = unique(mtcars$cyl) ) ) ) parcoords( mtcars ,rownames = FALSE ,brushMode = "1d-multi" ,brushPredicate = "OR" ,dimensions = list( cyl = list( title = "cylinder", tickValues = unique(mtcars$cyl) ) ) )
if(interactive()) { # simple example using the mtcars dataset data( mtcars ) parcoords( mtcars ) # various ways to change color # in these all lines are the specified color parcoords( mtcars, color = "green" ) parcoords( mtcars, color = "#f0c" ) # in these we supply a function for our color parcoords( mtcars , color = list( colorBy = "cyl" , colorScale = "scaleOrdinal" , colorScheme = "schemeCategory10" ) , withD3 = TRUE ) if(require('ggplot2', quietly = TRUE)) { parcoords( diamonds ,rownames = FALSE ,brushMode = "1d-axes" ,reorderable = TRUE ,queue = TRUE ,color= list( colorBy="cut" , colorScale = "scaleOrdinal" , colorScheme = "schemeCategory10" ) ,withD3 = TRUE ) } } library(parcoords) parcoords( mtcars, dimensions = list( cyl = list( title = "cylinder", tickValues = unique(mtcars$cyl) ) ) ) parcoords( mtcars ,rownames = FALSE ,brushMode = "1d-multi" ,brushPredicate = "OR" ,dimensions = list( cyl = list( title = "cylinder", tickValues = unique(mtcars$cyl) ) ) )
Output and render functions for using sunburst within Shiny applications and interactive Rmd documents.
parcoordsOutput(outputId, width = "100%", height = "400px") renderParcoords(expr, env = parent.frame(), quoted = FALSE)
parcoordsOutput(outputId, width = "100%", height = "400px") renderParcoords(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 sunburst |
env |
The environment in which to evaluate |
quoted |
Is |
if(interactive()) { #### filter proxy example ---- library(parcoords) library(shiny) ui <- tagList( textOutput("filteredstate", container=h3), parcoordsOutput("pc") ) server <- function(input, output, session) { rv <- reactiveValues(filtered = FALSE) output$pc <- renderParcoords({ parcoords(mtcars) }) observe({ # toggle between filtered and unfiltered every 2.5 seconds invalidateLater(2500) rv$filtered <- !isolate(rv$filtered) }) observeEvent(rv$filtered, { # create a proxy with which we will communicate between # Shiny and the parallel coordinates without a re-render pcp <- parcoordsProxy("pc") if(rv$filtered) { pcFilter( pcp, list( cyl = c(6,8), hp = list(gt = 200) ) ) } else { pcFilter(pcp, list()) } }) output$filteredstate <- renderText({ paste0("Filtered: ", rv$filtered) }) } shinyApp(ui = ui, server = server) ### center proxy example ---- library(shiny) library(parcoords) ui <- tags$div( parcoordsOutput("pc", width = 2500), style="width: 2500px;" ) server <- function(input, output, session) { # create a proxy with which we will communicate between # Shiny and the parallel coordinates without a re-render pcp <- parcoordsProxy("pc") output$pc <- renderParcoords({ parcoords(mtcars) }) pcCenter(pcp, 'drat') } shinyApp(ui=ui, server=server) ### hide/unhide proxy example ---- library(parcoords) library(shiny) ui <- tagList( selectizeInput( inputId = "columns", label = "Columns to Hide", choices = c("names",colnames(mtcars)), selected = "names", multiple = TRUE ), parcoordsOutput("pc"), checkboxInput("hidenames", label="Hide Row Names", value=TRUE), parcoordsOutput("pc2") ) server <- function(input, output, session) { output$pc <- renderParcoords({ parcoords(mtcars, rownames = FALSE, brushMode = "1d") }) output$pc2 <- renderParcoords({ parcoords(mtcars, rownames = FALSE) }) pcUnhide observeEvent(input$columns, { # create a proxy with which we will communicate between # Shiny and the parallel coordinates without a re-render pcp <- parcoordsProxy("pc") pcHide(pcp, input$columns) }, ignoreInit = TRUE, ignoreNULL = FALSE) observeEvent(input$hidenames, { # create a proxy with which we will communicate between # Shiny and the parallel coordinates without a re-render pcp2 <- parcoordsProxy("pc2") if(input$hidenames) { pcHide(pcp2, "names") } else { pcUnhide(pcp2, "names") } }) } shinyApp(ui = ui, server = server) ### snapshot example ---- library(shiny) library(parcoords) ui <- tags$div( actionButton(inputId = "snapBtn", label = "snapshot"), parcoordsOutput("pc", height=400) ) server <- function(input, output, session) { # create a proxy with which we will communicate between # Shiny and the parallel coordinates without a re-render pcp <- parcoordsProxy("pc") output$pc <- renderParcoords({ parcoords(mtcars) }) observeEvent(input$snapBtn, { # create a proxy with which we will communicate between # Shiny and the parallel coordinates without a re-render pcp <- parcoordsProxy("pc") pcSnapshot(pcp) }) } shinyApp(ui=ui, server=server) }
if(interactive()) { #### filter proxy example ---- library(parcoords) library(shiny) ui <- tagList( textOutput("filteredstate", container=h3), parcoordsOutput("pc") ) server <- function(input, output, session) { rv <- reactiveValues(filtered = FALSE) output$pc <- renderParcoords({ parcoords(mtcars) }) observe({ # toggle between filtered and unfiltered every 2.5 seconds invalidateLater(2500) rv$filtered <- !isolate(rv$filtered) }) observeEvent(rv$filtered, { # create a proxy with which we will communicate between # Shiny and the parallel coordinates without a re-render pcp <- parcoordsProxy("pc") if(rv$filtered) { pcFilter( pcp, list( cyl = c(6,8), hp = list(gt = 200) ) ) } else { pcFilter(pcp, list()) } }) output$filteredstate <- renderText({ paste0("Filtered: ", rv$filtered) }) } shinyApp(ui = ui, server = server) ### center proxy example ---- library(shiny) library(parcoords) ui <- tags$div( parcoordsOutput("pc", width = 2500), style="width: 2500px;" ) server <- function(input, output, session) { # create a proxy with which we will communicate between # Shiny and the parallel coordinates without a re-render pcp <- parcoordsProxy("pc") output$pc <- renderParcoords({ parcoords(mtcars) }) pcCenter(pcp, 'drat') } shinyApp(ui=ui, server=server) ### hide/unhide proxy example ---- library(parcoords) library(shiny) ui <- tagList( selectizeInput( inputId = "columns", label = "Columns to Hide", choices = c("names",colnames(mtcars)), selected = "names", multiple = TRUE ), parcoordsOutput("pc"), checkboxInput("hidenames", label="Hide Row Names", value=TRUE), parcoordsOutput("pc2") ) server <- function(input, output, session) { output$pc <- renderParcoords({ parcoords(mtcars, rownames = FALSE, brushMode = "1d") }) output$pc2 <- renderParcoords({ parcoords(mtcars, rownames = FALSE) }) pcUnhide observeEvent(input$columns, { # create a proxy with which we will communicate between # Shiny and the parallel coordinates without a re-render pcp <- parcoordsProxy("pc") pcHide(pcp, input$columns) }, ignoreInit = TRUE, ignoreNULL = FALSE) observeEvent(input$hidenames, { # create a proxy with which we will communicate between # Shiny and the parallel coordinates without a re-render pcp2 <- parcoordsProxy("pc2") if(input$hidenames) { pcHide(pcp2, "names") } else { pcUnhide(pcp2, "names") } }) } shinyApp(ui = ui, server = server) ### snapshot example ---- library(shiny) library(parcoords) ui <- tags$div( actionButton(inputId = "snapBtn", label = "snapshot"), parcoordsOutput("pc", height=400) ) server <- function(input, output, session) { # create a proxy with which we will communicate between # Shiny and the parallel coordinates without a re-render pcp <- parcoordsProxy("pc") output$pc <- renderParcoords({ parcoords(mtcars) }) observeEvent(input$snapBtn, { # create a proxy with which we will communicate between # Shiny and the parallel coordinates without a re-render pcp <- parcoordsProxy("pc") pcSnapshot(pcp) }) } shinyApp(ui=ui, server=server) }
Creates a parcoords-like object that can be used to customize and control a parcoords that has already been rendered. For use in Shiny apps and Shiny docs only.
parcoordsProxy(parcoordsId, session = shiny::getDefaultReactiveDomain(), deferUntilFlush = TRUE)
parcoordsProxy(parcoordsId, session = shiny::getDefaultReactiveDomain(), deferUntilFlush = TRUE)
parcoordsId |
single-element character vector indicating the output ID of the parcoords to modify (if invoked from a Shiny module, the namespace will be added automatically) |
session |
the Shiny session object to which the map belongs; usually the default value will suffice |
deferUntilFlush |
indicates whether actions performed against this
instance should be carried out right away, or whether they should be held
until after the next time all of the outputs are updated; defaults to
|
Normally, you create a parcoords chart using the parcoords
function.
This creates an in-memory representation of a parcoords that you can customize.
Such a parcoords can be printed at the R console, included in an R Markdown
document, or rendered as a Shiny output.
In the case of Shiny, you may want to further customize a parcoords, even after it is rendered to an output. At this point, the in-memory representation of the parcoords is long gone, and the user's web browser has already realized the parcoords instance.
This is where parcoordsProxy
comes in. It returns an object that can
stand in for the usual parcoords object. The usual parcoords functions
can be called, and instead of customizing an in-memory representation,
these commands will execute on the live parcoords instance.
parcoords
horizontally based on column/variable through parcoordsProxy
Center parcoords
horizontally based on column/variable through parcoordsProxy
pcCenter(pc = NULL, dim = NULL)
pcCenter(pc = NULL, dim = NULL)
pc |
|
dim |
|
parcoords_proxy
parcoords
through parcoordsProxy
Filter parcoords
through parcoordsProxy
pcFilter(pc = NULL, filters = NULL)
pcFilter(pc = NULL, filters = NULL)
pc |
|
filters |
|
parcoords_proxy
parcoords
columns through parcoordsProxy
Hide parcoords
columns through parcoordsProxy
pcHide(pc = NULL, dim = NULL)
pcHide(pc = NULL, dim = NULL)
pc |
|
dim |
|
parcoords_proxy
parcoords
through parcoordsProxy
Download image of parcoords
through parcoordsProxy
pcSnapshot(pc = NULL)
pcSnapshot(pc = NULL)
pc |
|
parcoords_proxy
parcoords
columns through parcoordsProxy
Unhide parcoords
columns through parcoordsProxy
pcUnhide(pc = NULL, dim = NULL)
pcUnhide(pc = NULL, dim = NULL)
pc |
|
dim |
|
parcoords_proxy