Vegalite - 忽略 NaN 和空值

问题描述

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

显示空/空/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 transformisValid 来过滤掉每条线的无效值。不幸的是,这目前在重复图表中是不可能的(功能请求在这里:https://github.com/vega/vega-lite/issues/7398)。

相反,您可以使用 fold transform 后跟 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"}
  }
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...