piecewise scale in vega-lite

212 Views Asked by At

here's (fiddle or gist you can paste into vega editor) a vega-lite project i'm working on. it's an interactive map of zip codes that lets you view a timeline of covid infections.

the color and y-scale are symlog, but that overemphasizes some rare negative values in the dataset (i guess when the health department reverses previously declared positive cases).

enter image description here

i'd like to use a piecewise scale to give less magnification to negative values. but when i add the following to my y-encoding scale, it seems to collapse the data to a single y value.

{ "domain": [-0.2 , 0, 1.4]
, "range" : [-0.05, 0, 1.4]
}

enter image description here

so what's the right way to specify a piecewise scale?

a few other questions i have:

  • the selection colors for each zip are currently chosen as nominal sinebow entries by zip, but since zip codes are spatially correlated, selecting nearby zip codes yields unhelpfully similarly colored lines (green in the example above). i think it would be better to use n equally spaced sinebow entries for n selections, but how can these be computed at selection time?
  • is there any way to include the Line's point just when it is selected (not just using selection-dependent opacity or size), rather than including a separate Circle Mark layer filtered to the selection, as i have done? like setting the shape encoding to null or something?
  • is there any way to get a tooltip along the Lines, not just at datapoints? i see it would be ambiguous which point's data to inspect, but i would think Lines should address this.
  • looks like choropleth zoom+pan has been deferred for a couple years, even though vega can do it. what makes this so hard for vega-lite to pick up? are there any workarounds? i would consider switching to vega (also for new labeling support that's not yet in vega-lite), but what is the best way to do this? i happen to use hvega in haskell to generate my vega-lite and would rather continue to maintain as much as possible from there, is it possible to avoid switching to doing everything in vega, only using it when vega-lite is insufficient? i'm picturing something like a vega instruction to import from vega-lite...
1

There are 1 best solutions below

0
On

specify a piecewise scale?

currently range is not abstract, it is in concrete presentation units. in this case, 0 is at the top and goes positive downwards in pixels. i filed a proposal to change this here: https://github.com/vega/vega/issues/2954

n equally spaced sinebow entries for n selections, but how can these be computed at selection time?

filed feature request here: https://github.com/vega/vega-lite/issues/7014. i don't think order/number selected is available, but many parameters can take expressions as values that could in principle be evaluated after each selection. https://vega.github.io/vega-lite/docs/mark.html#color https://vega.github.io/vega-lite/docs/types.html#exprref perhaps a selection predicate could be used to count the number currently selected? https://vega.github.io/vega-lite/docs/predicate.html#selection-predicate

include the Line's point just when it is selected

on selection condition change it from False? https://vega.github.io/vega-lite/docs/line.html#properties or on selection draw a whole new line with different point, only way to have it draw on top of the unselected.

tooltip along the Lines, not just at datapoints?

https://github.com/vega/vega-lite/issues/6851#issuecomment-718103153

choropleth zoom+pan

waiting...