Git Product home page Git Product logo

parcoords's Introduction

CRAN status Travis build status

parcoords | htmlwidget for d3 parallel-coordinates chart

parcoords gives R users the very well designed and interactive parallel-coordinates chart for d3 with the infrastructure, flexibility, and robustness of htmlwidgets. parcoords began in the Building Widgets blog series Week 04 | Interactive Parallel Coordinates and has been refined and improved through production usage in various disciplines.

# from CRAN
# install.packages("parcoords")
# for the latest release
# devtools::install_github("timelyportfolio/parcoords")

library(parcoords)

data(mtcars)

parcoords(
  mtcars
  ,reorderable = TRUE
  ,brushMode = "2d-strums"
)

Code of Conduct

Please note that the 'parcoords' project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms. I would love for anyone to participate, but please let's be friendly and welcoming.

parcoords's People

Contributors

timelyportfolio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

parcoords's Issues

ylim control

Is it possible to add ylim control for each of the coordinates? (it could be a list with a two dimensional element for each of the coordinates)

This is important since sometimes (when scaling) we can get the outlier dictating the ylim.

Thanks!

Using brushReset()

Is there a way to call parcoords.brushReset() on a button click? I know it's possible to run custom Javascript using the tasksparameter, but it's my understanding that this can only be used to run Javascript code directly after the parcoords plot has been produced.

I've made a workaround by taking a dependency on a reactive value (v$reset <- runif(1)) that changes everytime the reset button is selected, but it's a little messy.

Problem with NAs in the first row

Thank you for a fantastic package!

There seems to be an odd error: If there is an NA in the first row, the plot doesn't render.

For example, this works:

df <- data.frame(a = 1:2, b = 3:4, c = c(5, NA))
parcoords::parcoords(df)

but this doesn't:

df <- data.frame(a = 1:2, b = 3:4, c = c(NA, 5))
parcoords::parcoords(df)

No Shiny output together with scatterD3

Hi,

I get no output using the code below where I use parcoords together with scatterD3 in a Shiny app. If I comment out scatterD3Output, the parcoords graph appears. With normal plotOutput it works fine together. Strange.

`##devtools::install_github("timelyportfolio/parcoords", force=TRUE)
library(shiny)
library(parcoords)
require(scatterD3)

ui = shinyUI(
fluidPage(
##plotOutput( "dot1"), ## OK!
scatterD3Output("dot2"), ## not OK!
parcoordsOutput("parcoords")
)
)

server = function(input,output,session) {
output$parcoords = renderParcoords(parcoords( iris[,c(5,1:4)]))
output$dot1 <- renderPlot( plot( iris[,1], iris[,2]))
output$dot2 <- renderScatterD3( scatterD3( iris[,1], iris[,2] ))
}

shinyApp(ui,server)
`

calculations based on selected data with Shiny

when using this widget (great work, btw!) with a Shiny app, is it possible to return subsets of values based on selections along the axes? I'd like to perform some calculations based on the sliders.

add to CRAN

cc @carbonmetrics

parcoords seems to be one of the top two most popular htmlwidgets from last year's project. Given it's popularity, CRAN submission might be worth the effort. Please respond with comment or Github reaction if you care.

Is it possible to color lines based a field that is not rendered as an axis?

I'm using color = list(colorBy = "somefactor")) to color the lines in the parallel coordinates diagram, but I don't want that factor to be rendered as an axis in the diagram. Is that possible? Ive tried linking to a vector outside the dataframe rendered by parcoords without success. This would be quite helpful

Alignment problems in rmarkdown presentation

I'm using reveal.js presentation library in RStudio.

The following rmarkdown demonstrates a problem related to the horizontal alignment of the parcoords widget.

How to fix that?


---
title: "Par Coordinates"
output: revealjs::revealjs_presentation

---


```{r parcoords, echo=FALSE}
library(parcoords)
data("mtcars")
p <- parcoords(mtcars,autoresize = T,reorderable = T,brushMode = "1D-axes-multi")

htmltools::tagList(p)

Edit axis titles

In syntagmatic's parallel coordinates library, you can edit axis titles by using the dimensions function.

Is there any way of editing the axis titles in parcoords?

shiny rendering failing

parcoords doesn't render in Shiny (but it works beautifully in RStudio viewer / localhost browser).

In javascript console log I get error "uncaught TypeError: string is not a function", the shiny bindings / parcoords.js:67 line is the offender. I have made a pull request for the fix.

        d3.keys(d3.nest().key(function(d){return d[x.options.color.colorBy]}).map(x.data)).map(function(c){
      colors[c] = colorScale(c);

Change '=colorScale(c)' to '=colorScale[c]' and it works.

I think this is fantastic btw, keep the widgets coming... I really love parcoords!

Minimum reproducible example below (the parcoords piece works on its own, just not wrapped in shiny until you fix the bracket issue):

# app.R
# minimal shiny app with parcoords
library(shiny)
library(parcoords)

data(mtcars)

ui <- basicPage(
        absolutePanel(width=1000, "Parcoords in shiny", parcoordsOutput("par") )
    )

server <- function(input, output) {
   # simple parcoords  
    output$par <- renderParcoords({
        parcoords(mtcars, rownames = T
                  , brushMode = "1d-axes"
                  , reorderable = T
                  , queue = F
                  , color = list(
                      colorBy = "cyl"
                      , colorScale = htmlwidgets::JS("d3.scale.category20()"))
                  )
    })
}

shinyApp(ui, server)

And session info after running the above code:
NB I'm Win 8.1 64 bit.

Session info ---------------------------------------------------------------------------------------------------------
setting value
version R version 3.1.2 (2014-10-31)
system x86_64, mingw32
ui RStudio (0.99.235)
language (EN)
collate English_United Kingdom.1252
tz Europe/London

Packages -------------------------------------------------------------------------------------------------------------
package * version date source
devtools * 1.7.0 2015-01-17 CRAN (R 3.1.2)
digest * 0.6.8 2014-12-31 CRAN (R 3.1.2)
htmltools * 0.2.6 2014-09-08 CRAN (R 3.1.2)
htmlwidgets * 0.3.2 2014-12-09 CRAN (R 3.1.2)
httpuv * 1.3.2 2014-10-23 CRAN (R 3.1.2)
jsonlite * 0.9.14 2014-12-01 CRAN (R 3.1.2)
mime * 0.2 2014-09-26 CRAN (R 3.1.2)
parcoords 0.1 2015-02-10 Github (6817d24)
R6 * 2.0.1 2014-10-29 CRAN (R 3.1.2)
Rcpp * 0.11.4 2015-01-24 CRAN (R 3.1.2)
RJSONIO * 1.3-0 2014-07-28 CRAN (R 3.1.2)
rstudioapi * 0.2 2014-12-31 CRAN (R 3.1.2)
shiny 0.11.0.9001 2015-02-04 Github (rstudio/shiny@424696c)
xtable * 1.7-4 2014-09-12 CRAN (R 3.1.2)
yaml * 2.1.13 2014-06-12 CRAN (R 3.1.2)

See / download selected data

It would be great to be able to see which exact rows are selected after brushing across several variables. Would there be any way to represent this on the screen, or to at least pass on the items still selected so that they can be downloaded in a dump file?

Add mouseover

Great, useful library!!

With a large number of observations, it becomes quite difficult to read the sample labels. A plotly-like mouseover functionality (which afik is not implemented for plotly's own parcoord plots) would be really helpful in that regard. This should, e.g., show the sample name (row name) and perhaps the exact value for the axis closest to the mouse position upon moving the cursor over the respective line. One could also limit this to lines that were selected by the brush selection to make it even less crowded.

An alternative would be to only show the row names/sample labels in the row names axis of the lines that are currently selected by the brush (and hide the all other labels).

Edit: similar to this here: http://bl.ocks.org/mostaphaRoudsari/b4e090bb50146d88aec4

parcoord PKG: double-click an axis name does not reorder tick values (mtcars cyl axis)

Hi Kenton!

Your Intro to โ€˜parcoordsโ€™
article (and the pkg itself),
is great!.

I noticed the following bug(?)
in the mtcars display:

If I select (for ex.),
the Porsche 914-2 model,
it correctly displays: 4 in the cyl axis.

But if the user wants to reorder that cyl axis
and double-clicks
on the axis name:
cyl ,
the line will now show (incorrectly)
the value: 8 in the cyl axis!.
But the Porsche has 4 cylinders,
not 8...

In other words:
the Porsche orange line has moved
but the axis tick values (4,6,8),
have not been reordered!.

The value 4
is still at the bottom of the cyl axis
and 8 is still at the top,
after reordering the cyl axis.

This will happen for either:
reorderable = FALSE or TRUE...

Here's the Code to reproduce:

start of R code

library(shiny)
library(parcoords)
library(d3r)

ui <- fluidPage(
    sidebarLayout(
        sidebarPanel(
           
        ),
       
        mainPanel(
            parcoordsOutput("par_plot")
        )
    )
)

server <- function(input, output) {
   
    output$par_plot<- renderParcoords({
        data(mtcars)
        parcoords(mtcars, rownames = TRUE, brushMode = "1d-axes-multi",   reorderable = FALSE,
                  alphaOnBrushed = 0.15,
                  color = list(
                      colorBy = "cyl",
                      colorScale = "scaleOrdinal",
                      colorScheme = "schemeCategory10"
                  ),
                  withD3 = TRUE)
    })
}

shinyApp(ui = ui, server = server)

** end of R code **

Help, Kenton!

RAY
San Francisco
Rstudio, R - latest versions
Ubuntu Linux 20.04
parcoords PKG 1.0.0

ordering for ordinal and continuous variables along vertical axes

Is it possible to change the ordering of values along the various Y-axes in a parcoords plot?

  • For a categorical factor variable, it seems that when the plot is rendered, it is in descending order of frequency and does not respect the ordering of the factor variable. Is there a way to pass that through?
  • Similarly, it appears that all continuous values are organized in descending order. Is it possible to vary that, on an axis by axis basis?

This is achieved in d3, as I understand, by passing d3.scale.linear().range(); such as:

var dimensions = [
  {
    name: "name",
    scale: d3.scale.ordinal().rangePoints([0, height]),
    type: "string"
  },
  {
    name: "economy (mpg)",
    scale: d3.scale.linear().range([0, height]),
    type: "number"
  }
]

using the new color option in version 1.0.0

Hi,

I see that the new color option is easier to use:

parcoords(
mtcars
, color = list(
colorBy = "cyl"
, colorScale = "scaleOrdinal"
, colorScheme = "schemeCategory10"
)
, withD3 = TRUE
)

However, it is somewhat less flexible. As in the example below, how can I define custom bins and assign custom colors to each bin?

diamonds[sample(1:nrow(diamonds),1000),] %>%
select( carat, color, cut, clarity, depth, table, price, x, y, z) %>%
parcoords(
rownames = F # turn off rownames from the data.frame
, brushMode = "2D-strums"
, reorderable = T
, queue = T
, color = list(
colorBy = "carat"
,colorScale = htmlwidgets::JS(sprintf('
d3.scale.threshold()
.domain(%s)
.range(%s)
'
,jsonlite::toJSON(seq(0,round(max(diamonds$carat))))
,jsonlite::toJSON(RColorBrewer::brewer.pal(6,"PuBuGn"))
))
)
)

Brush selection return nothing inside a Shiny module

Hi, I recently made the move to Shiny modules and was still able to display the 'parcoords' plot and doing the line selection. However, the "input$ParcoodPlot_brushed_row_names" variable was empty afterward and I couldn't find a way to retrieve the list of names.

I suspect that the namespace wrapping required by a Shiny module has something to do with this behavior. Anyone figure out how to solve this problem?

in `Shiny` `JS` getting passed as a string

@jcheng5, @ramnathv, @yihui | I wondered if you might be able to add some insight on this strange situation. When using parcoords, the JS_EVALS get passed as a character and fail when rendered with renderParcoords in Shiny, but work perfectly even in Shiny when rendered statically with parcoords. Here is a simple example that fails on my machine. sessionInfo() pasted below code. I'll keep digging but I have not found anything so far.

library(shiny)
library(parcoords)

p1 <- parcoords(
  mtcars,
  ,color = list(
    colorScale=htmlwidgets::JS('d3.scale.category10()')
    , colorBy = "cyl"
  )
)

# test p1 ; should color by cyl
p1

# JS_evals
htmlwidgets:::JSEvals(p1$x)

ui <- shinyUI(fluidPage(
  tags$h1("shiny")
  ,parcoordsOutput("DiamondPlot")
  ,tags$h1("static")
  ,p1
))

server <- function(input, output, session) {
  output$DiamondPlot <- renderParcoords({
    p1
  })
}

shinyApp(ui,server)
R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] parcoords_0.1     shiny_0.11.1.9002

loaded via a namespace (and not attached):
 [1] digest_0.6.4      htmltools_0.2.7   htmlwidgets_0.3.2 httpuv_1.3.2      jsonlite_0.9.14  
 [6] mime_0.2          R6_2.0.1          Rcpp_0.11.4.6     RJSONIO_1.3-0     tools_3.1.2      
[11] xtable_1.7-4      yaml_2.1.13 

large numbers of observations, slow response/render times

Im plotting approx ~4500 observations on a parcoords figure, running on a shiny server. Performance really slows down with slow rendering times. Im wondering if you've run into similar issues or have recommendations for dealing with larger numbers of observations?

parcoords has stopped working

Always worked perfectly, but now there is no more interactivity.
I have tried to go back to an earlier version of rmarkdown/knitr, as that is the only thing that I can think of that has changed - I could not render (requires update of rmarkdown).

library(parcoords)  
data( mtcars )
parcoords( mtcars )

> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 15.04

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=nl_NL.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=nl_NL.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=nl_NL.UTF-8      
 [8] LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=nl_NL.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] rsconnect_0.4.1.11 htmltools_0.3.5    tools_3.2.3        yaml_2.1.13        Rcpp_0.12.4        rmarkdown_0.9.5    knitr_1.12.3       digest_0.6.9    

Brush does not appear to reset correctly with crosstalk and DT

So I think something weird is going on with the clearing the brush from parcoords. Consider the example below.

  1. Create a brush on the parcoords viz and note how many records are filtered in the DT output (e.g., "Showing N of 10 of 150 entries").
  2. Clear that brush (by clicking on parcoords) and notice how things do not reset in the DT output.

NOTE: If you click on the DT output after the brush, things seems to correct themselves?

---
title: "Parcoords and Crosstalk"
output: html_document
runtime: shiny
---

```{r setup, include=FALSE}
library(shiny)
library(tidyverse)
library(parcoords)
library(crosstalk)
library(DT)
```

## Here's some stuff

```{r stuff, echo = FALSE}
checkboxGroupInput(
        "cb_vars", 
        "Select variables",
        choices = colnames(iris),
        inline = TRUE,
        selected = colnames(iris)[1:2]
    )

parcoordsOutput("pc_plot")

dataTableOutput("tbl")

iris_react <- reactive({
    iris %>% 
        select(input$cb_vars)
})
    
shared_iris <- SharedData$new(iris_react)

output$pc_plot <- renderParcoords({
    parcoords(
        shared_iris,
        rownames = FALSE,
        brushMode = "1D-axes",
        alpha = 0.3
    )
})

output$tbl <- renderDataTable({
  shared_iris
},
  style = "bootstrap",
  class = "compact",
  width = "100%",
  rownames = FALSE,
  server = FALSE,
  options = list(
    dom = NULL
  )
)

```

Crosstalk: parcoords can't respond to filter_slider

Based on this block, it looks like parcoords/feature/crosstalk can't respond to filter events. The code below seems to corroborate this (if I'm implementing everything correctly). Is that the case currently? If so, any plans to include this feature down the road?

library(parcoords)
library(crosstalk)
library(htmltools)

sd <- SharedData$new(mtcars)

browsable(tagList(
  filter_slider("wt", "Weight", sd, column = ~wt, step = 0.2),
  parcoords(sd, brushMode = "1d", height = 300, width = 500)
))

Setting color with crosstalk dataset will prevent parcoords display

When you use parcoords with crosstalk and set a color dimension, the widget will not appear. But when you add a second parcoords plot that does not use crosstalk, it will render all plots perfectly fine.

Minimal Example

sessionInfo() output
R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.1 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] magrittr_1.5

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.0       xfun_0.18              purrr_0.3.4            colorspace_1.4-1      
 [5] vctrs_0.3.4            generics_0.0.2         viridisLite_0.3.0      htmltools_0.5.0       
 [9] yaml_2.2.1             plotly_4.9.2.1         rlang_0.4.8            later_1.1.0.1         
[13] pillar_1.4.6           glue_1.4.2             lifecycle_0.2.0        stringr_1.4.0         
[17] munsell_0.5.0          gtable_0.3.0           htmlwidgets_1.5.2.9000 evaluate_0.14         
[21] labeling_0.4.2         knitr_1.30             d3r_0.9.0              fastmap_1.0.1         
[25] httpuv_1.5.4           crosstalk_1.1.0.1      Rcpp_1.0.5             xtable_1.8-4          
[29] renv_0.12.0            promises_1.1.1         scales_1.1.1           DT_0.16               
[33] BiocManager_1.30.10    jsonlite_1.7.1         mime_0.9               farver_2.0.3          
[37] servr_0.20             ggplot2_3.3.2          digest_0.6.26          stringi_1.5.3         
[41] xaringan_0.18          dplyr_1.0.2            shiny_1.5.0            grid_4.0.3            
[45] tools_4.0.3            lazyeval_0.2.2         tibble_3.0.4           parcoords_1.0.0       
[49] crayon_1.3.4           tidyr_1.1.2            pkgconfig_2.0.3        ellipsis_0.3.1        
[53] data.table_1.13.2      rmarkdown_2.5          httr_1.4.2             rstudioapi_0.11       
[57] R6_2.4.1               compiler_4.0.3   

Comment in the no-crosstalk chunk for both widgets to work.

---
title: "Parcoords and Crosstalk"
output: html_document
---

```{r parcoords}
shared_iris <- crosstalk::SharedData$new(iris)
parcoords::parcoords(
  shared_iris,
  color = list(colorBy = "Species"),
  withD3 = TRUE
)
```

```{r dt}
DT::datatable(shared_iris)
```

```{r no-crosstalk}
# parcoords::parcoords(
#   iris,
#   color = list(colorBy = "Species"),
#   withD3 = TRUE
# )
```

Screenshots

Without no-crosstalk chunk.

image

With no-crosstalk chunk.

image

Is it possible to sort the row names along the initial y-axis?

parcoords has a great application for a current project!

But any initial sorting within the data frame seems to get overridden when passed to parcoords(). The widget then sorts the initial y-axis in descending alphabetical order. Are there any options to control this? How could I run any of the parcoords examples here where 'AMC Javelin' appears at the top and 'Volvo 142E' appears at the bottom?

Rendering in Windows

Works fantastic in Linux, zero issues.
html files sent to Windows computers give mixed results. Chrome works as intended, Internet Explorer shows nothing. Firefox shows plot, axes can be moved around, but no selection is possible [I use 1D axis multi].

README.md nit

Installation needs to be

devtools::install_github("timelyportfolio/parcoords")

not

devtools::install("timelyportfolio/parcoords")

:-)

Sharon

Mapping specific colors to specific values of 'colorBy'

Hello,

I'd like to be able to specify colors for specific values of the colorBy variable. Is this possible? I understand that you can specify the variable to color with colorBy = variable. But could you pass for e.g. a named vector where the name is the unique value in the variable and the value is the color? This is commonly done in other plotting packages to enforce colors for specific values.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.