Vegalite - 忽略 NaN 和空值

Vegalite - ignore NaN and empty Values

我是 Vegalite 的新手并且进展顺利,但我正在努力从我的输入数据中找到 omit/ignore NaN 和空字段值的正确方法。在我的示例中,我的字段包含沿 X 轴的胆固醇面板,而 Y 轴表示采集每个血样的日期。由于一些示例不完整,字段为空,我希望我的折线图简单地继续到下一个有效点,而不是中断并留下间隙。

显示 null/empty/NaN 数据的折线图示例;

Example of broken line chart

{  "title": "Blood Panel Data",  
  "width": 600,
  "height": 300,
 
  "config": {
     "axis": {
         "grid": true,
         "gridColor": "DarkSlateGrey",
          "background": "white"}},
  
 "repeat": {
   "layer": ["Cholesterol","Triglycerides","HDL Chol","LDL Chol","Non-HDL","Cholesterol/HDL-C Ratio"]},
        
 "spec": {

 "mark" : {
  "type" : "line",
  "interpolate": "monotone",
   "point": true },
  
   
   "encoding": {
     "x": {"field": "Date", "type": "temporal"},
     "y": {
       "field": {"repeat": "layer"},
       "type": "quantitative",
       "title": "Value"},
       
       "color": { "datum": {"repeat": "layer"}, "type": "nominal" }        
       
   }
 }
}

对于没有经验的用户来说,通读 Vegalite 文档真的很困难 - 因为他们的大多数示例都会跳入复杂的方法论。我假设我需要通过转换忽略空数据值?但是我执行此操作的尝试一直失败。

感谢对此的任何帮助。我的示例数据在 Airtable 上。

Example Source Data layout

在重复层图表中执行此操作的最佳方法是使用 filter transform with isValid to filter out the invalid values for each line. Unfortunately, this is currently not possible within a repeated chart (the feature request is here: https://github.com/vega/vega-lite/issues/7398)。

相反,您可以使用 fold transform followed by a filter transform; 实现大致相同的效果;对于您的图表,它可能看起来像这样:

{
  "title": "Blood Panel Data",
  "width": 600,
  "height": 300,
  "config": {
    "axis": {"grid": true, "gridColor": "DarkSlateGrey", "background": "white"}
  },
  "transform": [
    {
      "fold": [
        "Cholesterol",
        "Triglycerides",
        "HDL Chol",
        "LDL Chol",
        "Non-HDL",
        "Cholesterol/HDL-C Ratio"
      ],
      "as": ["Column", "Value"]
    },
    {"filter": "isValid(datum.Value)"}
  ],
  "mark": {"type": "line", "interpolate": "monotone", "point": true},
  "encoding": {
    "x": {"field": "Date", "type": "temporal"},
    "y": {"field": "Value", "type": "quantitative"},
    "color": {"field": "Column", "type": "nominal"}
  }
}