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

Rank and/or quantile transform #483

Closed
mbostock opened this issue Aug 4, 2021 · 8 comments
Closed

Rank and/or quantile transform #483

mbostock opened this issue Aug 4, 2021 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@mbostock
Copy link
Member

mbostock commented Aug 4, 2021

It’d nice to have a map transform that converts quantitative values into ranks (1, 2, 3, …) or the equivalent p-quantile in [0,1]. This would be an alternative to the quantile scale.

@mbostock mbostock added the enhancement New feature or request label Aug 4, 2021
@Fil
Copy link
Contributor

Fil commented Aug 4, 2021

Should this be part of d3-array?
https://observablehq.com/d/c1eb24e6680046d7

@mbostock
Copy link
Member Author

mbostock commented Aug 4, 2021

I figured we would build it and see if it’s useful before we decide.

One nuance on implementation: if the same value is repeated, then they should have the same rank, and ranks should be skipped. So for example [3, 1, 3, 4, 2, 0] is mapped to [4, 2, 4, 6, 3, 1] (assuming 1-based ranking). Also I think all non-comparable values would need to be replaced with NaN (or undefined?).

@mbostock
Copy link
Member Author

mbostock commented Aug 4, 2021

Also if we use d3.sort we will need to fix d3/d3-array#217 such that all undefined values (null, NaN, and undefined) are moved to the end.

@Fil
Copy link
Contributor

Fil commented Aug 4, 2021

I've added a "same value" test (with a test on ! a <= b to make sure two Date objects representing the same date have the same rank).

I'm not sold on starting at 1. I see the cosmetic appeal, but it makes this slightly more difficult to, for example, use the rank to lookup a value in another array "🥇🥈🥉"[rank].

@mbostock
Copy link
Member Author

mbostock commented Aug 4, 2021

I’m not convinced we want 1-based ranking either. That was just my first thought… we can start with 0-based if you like.

@Fil
Copy link
Contributor

Fil commented Aug 4, 2021

The inherent difficulty of writing this "simple" function makes me think it should be in d3-array. And it's already nice to use in Plot:

Capture d’écran 2021-08-04 à 18 37 52

@Fil Fil self-assigned this Aug 12, 2021
@Fil
Copy link
Contributor

Fil commented Aug 17, 2021

pull-request for d3.rank d3/d3-array#228

@mbostock
Copy link
Member Author

mbostock commented Jan 1, 2022

Added in #570.

@mbostock mbostock closed this as completed Jan 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants