素食主义者-忽略NaN和空值



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

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

折线图示例

{  "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上。

示例源数据布局

在重复图层图中执行此操作的最佳方法是使用带有isValid的过滤器变换来过滤掉每一行的无效值。不幸的是,在重复的图表中,这目前是不可能的(功能请求如下:https://github.com/vega/vega-lite/issues/7398)。

相反,您可以使用折叠变换和滤波变换来实现大致相同的效果;对于你的图表,它可能看起来像这样:

{
"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"}
}
}

最新更新