scalaapache-sparkvegavega-litevegas-viz

Vegas (Scala/Spark/Vega) color every data point


Vegas("A scatterplot").
  withDataFrame(neuronnet_activation_df).
  mark(Point).
  encodeX("s", Quantitative).
  encodeY("d", Quantitative).
  encodeColor(field="feature_0_prediction",scale=Scale(rangeNominals=List("#c41f01", "#00c610"))).
  show

Is there away to plot each point with a specifiy RGB or aRGB value? I have the colors already computed, so I do not need to use ranges, also the color range is not linear for my data.


Solution

  • I'm not certain how this maps onto the Vegas syntax, but in Vega-Lite you can do this by passing color codes as data, and setting the color scale to null. For example:

    {
      "data": {
        "values": [
          {"s": 1, "d": 1, "color": "#c41f01"},
          {"s": 3, "d": 3, "color": "#00c610"}
        ]
      },
      "mark": {"type": "circle", "size": 200},
      "encoding": {
        "color": {"type": "nominal", "field": "color", "scale": null},
        "x": {"type": "quantitative", "field": "s"},
        "y": {"type": "quantitative", "field": "d"}
      },
      "$schema": "https://vega.github.io/schema/vega-lite/v2.6.0.json"
    }
    

    Vega-Lite output