Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smoothness for lines in parallel plot #12

Open
sherrylau opened this issue Oct 13, 2015 · 4 comments
Open

Smoothness for lines in parallel plot #12

sherrylau opened this issue Oct 13, 2015 · 4 comments

Comments

@sherrylau
Copy link

Hi,

My current plot is like this:

  parcoords(clusterFeatureData,
            rownames=F,
            reorderable=T,
            margin=list(top=20, bottom=20, left=0, right=0),
            alpha=0.9,
            color="#CC3333",
            brushMode="1D-axes-multi",
            width="1080",
            height="400")

Is that possible to change the smoothness like the one here?
https://syntagmatic.github.io/parallel-coordinates/

@timelyportfolio
Copy link
Owner

@sherrylau, sorry it took me so long to get to this. If you are still there, here are some ways to achieve this. If popular enough, I'll add to parcoords itself.

library(parcoords)

pc <- parcoords(mtcars)

# manually add smoothness
pc$x$options$smoothness <- 0.3
library(htmltools)

pc$dependencies <- list(
  htmlDependency(
    name = "sylvester",
    version = "0.1.3",
    src = c(href="//cdnjs.cloudflare.com/ajax/libs/sylvester/0.1.3/"),
    script = "sylvester.min.js"
  )
)
pc

# make a function to add smoothness
add_smoothness <- function(pc, smoothness = 0){
  stopifnot(
    inherits(pc,"parcoords"),
    (smoothness >= 0 && smoothness <= 1)
  )

  pc$x$options$smoothness <- smoothness

  pc$dependencies[[length(pc$dependencies) + 1]] <- htmlDependency(
      name = "sylvester",
      version = "0.1.3",
      src = c(href="//cdnjs.cloudflare.com/ajax/libs/sylvester/0.1.3/"),
      script = "sylvester.min.js"
    )
  pc
}

pc2 <- parcoords(mtcars)
add_smoothness(pc2, 0.1)

@ZJUguquan
Copy link

ZJUguquan commented Aug 22, 2017

@timelyportfolio , Hi,

I have followed your advice and the lines become smoother as planed. However, it seems that the smoother parcoords photo can not be render by shiny using renderParcoords and parcoordsOutput. If I do like this, all polylines disappear... >_<

The R codes is below,

library(shiny)
library(parcoords)
library(htmltools)
add_smoothness <- function(pc, smoothness = 0){
  stopifnot(
    inherits(pc,"parcoords"),
    (smoothness >= 0 && smoothness <= 1)
  )
  pc$x$options$smoothness <- smoothness
  pc$dependencies[[length(pc$dependencies) + 1]] <- htmlDependency(
    name = "sylvester",
    version = "0.1.3",
    src = c(href="//cdnjs.cloudflare.com/ajax/libs/sylvester/0.1.3/"),
    script = "sylvester.min.js"
  )
  pc
}

shinyApp(
  ui = fluidPage(parcoordsOutput('pcoords')),
  server = function(input, output){
    output$pcoords <- renderParcoords({
      pc <- parcoords(mtcars)
      pc2 <- add_smoothness(pc, 0.2)
      return(pc2)
    })
  }
)

so what should I do?

Waiting for your reply~

@timelyportfolio
Copy link
Owner

timelyportfolio commented Aug 24, 2017

It appears the dependency attached to the htmlwidget is not working. I am a little surprised by this, but fortunately we can take a different approach. Try this way.

library(shiny)
library(parcoords)
library(htmltools)
add_smoothness <- function(pc, smoothness = 0){
  stopifnot(
    inherits(pc,"parcoords"),
    (smoothness >= 0 && smoothness <= 1)
  )
  pc$x$options$smoothness <- smoothness
  pc
}

shinyApp(
  ui = tagList(
    htmlDependency(
      name = "sylvester",
      version = "0.1.3",
      src = c(href="//cdnjs.cloudflare.com/ajax/libs/sylvester/0.1.3/"),
      script = "sylvester.min.js"
    ),
    fluidPage(parcoordsOutput('pcoords'))
  ),
  server = function(input, output){
    output$pcoords <- renderParcoords({
      pc <- parcoords(mtcars)
      pc2 <- add_smoothness(pc, 0.2)
      return(pc2)
    })
  }
)

@ZJUguquan
Copy link

@timelyportfolio Thank you very much! It works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants