Smoothness for lines in parallel plot
sherrylau opened this issue · 4 comments
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/
@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)
@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~
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)
})
}
)
@timelyportfolio Thank you very much! It works!