vega / vega-lite

A concise grammar of interactive graphics, built on Vega.
https://vega.github.io/vega-lite/
BSD 3-Clause "New" or "Revised" License
4.68k stars 611 forks source link

Add jittering in the shape of a density/KDE for point marks #8067

Open joelostblom opened 2 years ago

joelostblom commented 2 years ago

I would like to distribute points in the shape of a density / violin cloud as in this picture image Python code and Vega-Lite spec in this comment

I originally opened an issue for this in the Vega repo https://github.com/vega/vega/issues/3311 because I wasn't sure whether it was yet possible in Vega. I just heard back from jheer that it is actually possible to create this in Vega. Please refer to that issue for more details, but in brief this is what he said:

Here is an implementation in Vega.

The approach taken is:

  • Compute the density, and generate a rounded value to serve as a lookup key.
  • For the original points, bin the data in a manner that matches the density samples.
  • Extend the original points by performing a lookup against the density values.
  • Use the density values to scale the random jitter.

This works in Vega, but I don't think it can be expressed in Vega-Lite or Altair because the secondary data input to the lookup transform does not allow additional transforms to be applied.

Would it be possible to support this Vega expression in Vega-Lite by addressing the last comment in the quote above? Would this require a major or minor change in Vega-Lite?

cc: @kanitw since we talked about this a little in https://github.com/vega/vega-lite/issues/4703#issuecomment-927257382

domoritz commented 2 years ago

I think it would be great to support additional transforms in lookup. I remember that there were similar requests in the past.

hcoohb commented 2 years ago

That would be an awesome feature indeed!