How to transform a secondary data source inside a lookup transform?

Viewed 115

How do we transform a secondary data source inside a lookup transform? I want to apply a transform inside the secondary data source itself which is test.csv.

Here's the test.csv file with few sample data

country_txt success
Australia 1
Australia 2
England 0

Here's the incomplete vega.json file without the mark property but it should be enough

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "title": "OK",
  "width": 1080,
  "height": 1080,
  "data": {
    "url": "https://cdn.jsdelivr.net/npm/world-atlas@2/countries-110m.json",
    "format": {
      "type": "topojson",
      "feature": "countries"
    }
  },
  "transform": [
    {
      "lookup": "properties.name",
      "from": {
        "data": {
          "url": "data\\test.csv"
        },
        "key": "country_txt",
        "fields": [
          "country_txt"
        ]
      }
    }
  ]

I want to aggregate the counts of the countries appearing in test.csv before performing a lookup transform with my primary data source. So how do we do that? I tried transforming it directly before the key property declaration but it is not supported. I just started Vega Lite and tried reading the documentation but there's nothing I can use over there so would appreciate the help.

1 Answers
  "data": [
    {
      "name": "test",
      "url": "data\\test.csv",
      "format": {"type": "csv", "parse": "auto"},
      "transform": [
        {"type": "aggregate","groupby":["country_txt"]}
      ]
    },
    {
      "name": "map",
      "url": "https://cdn.jsdelivr.net/npm/world-atlas@2/countries-110m.json",
      "format": {"type": "topojson", "feature": "countries"},
      "transform": [
        { "type": "lookup", "from": "test", "key": "country_txt", "fields": ["properties.name"],"as":["Count"] }
      ]
    }
  ],

Solved it by declaring my datasets inside an array of data property.

Related