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

Mapping specific colors to specific values of 'colorBy' #46

Open
processir opened this issue Dec 3, 2021 · 5 comments
Open

Mapping specific colors to specific values of 'colorBy' #46

processir opened this issue Dec 3, 2021 · 5 comments

Comments

@processir
Copy link

processir commented Dec 3, 2021

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.

@timelyportfolio
Copy link
Owner

timelyportfolio commented Dec 17, 2021

@processir sorry I missed this. Good question, and I see how this can be difficult, since there are no good examples or documentation. Here is a quick example, but unfortunately this does not work as intended. I'll try to get a fix by this weekend.

library(parcoords)

parcoords(
  mtcars,
  color = list(
    colorBy = "cyl",
    colorScale = "scaleOrdinal",
    colorScheme = c("purple","blue","green"),
    colorDomain = c(4,6,8)
  ),
  withD3 = TRUE
)

@timelyportfolio
Copy link
Owner

@processir I made a change that I think will allow us to specify domain as you suggest. Please run same example from above and the cyl == 4 should show as purple.

@processir
Copy link
Author

Hey @timelyportfolio , thanks for your help. Your example seems to work on my end. However, I noticed that the brushMode using 1d-axes-multi does not work with this example while 1d-axes does when the reorderable = TRUE parameter is set. Do you know if there is a quick fix to this?

# works
parcoords(
  mtcars,
  brushMode = "1D-axes",
  reorderable = TRUE,
  color = list(
    colorBy = "cyl",
    colorScale = "scaleOrdinal",
    colorScheme = c("purple","blue","green"),
    colorDomain = c(4,6,8)
  ),
  withD3 = TRUE
)

# does not work
parcoords(
  mtcars,
  brushMode = "1D-axes-multi",
  reorderable = TRUE,
  color = list(
    colorBy = "cyl",
    colorScale = "scaleOrdinal",
    colorScheme = c("purple","blue","green"),
    colorDomain = c(4,6,8)
  ),
  withD3 = TRUE
)

@timelyportfolio
Copy link
Owner

@processir Glad the color fix worked. 1d-multi-axes is same issue as #45. I tried to quickly patch last night when working on color but did not work. Unfortunately this is a more complicated issue requiring changes to underlying library. I hope to fix by year end.

@jtr13
Copy link

jtr13 commented Mar 3, 2022

This is really helpful... thanks! Both examples (brushMode = "1D-axes" and brushMode = "1D-axes-multi") work with color for me.

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