有没有办法在图和X轴之间添加换行符(vega-lite)

时间:2019-12-19 02:19:57

标签: vega-lite

我不确定是否有意义,但是可以在绘图的起点和X轴之间添加一个换行符。

例如

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "width": {"step": 10},
  "height": 120,
  "data": {"url": "data/cars.json"},
  "mark": "area",
  "encoding": {
    "x": {"field": "Name", "type": "nominal", "scale": {"round": false}},
    "y": {"aggregate": "count", "type": "quantitative"}
  }
}

enter image description here

希望的输出: enter image description here

2 个答案:

答案 0 :(得分:1)

一种方法是添加一个scale.domain参数:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "width": {"step": 10},
  "height": 120,
  "data": {"url": "data/cars.json"},
  "mark": "area",
  "encoding": {
    "x": {"field": "Name", "type": "nominal", "scale": {"round": false}},
    "y": {"aggregate": "count", "type": "quantitative", "scale": {"domain": [-0.5, 6]}}
  }
}

enter image description here

另一种方法是使用yy2编码来设置面积图的底值:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "width": {"step": 10},
  "height": 120,
  "data": {"url": "data/cars.json"},
  "mark": "area",
  "transform": [{"calculate": "0.1", "as": "bottom"}],
  "encoding": {
    "x": {"field": "Name", "type": "nominal", "scale": {"round": false}},
    "y": {"aggregate": "count", "type": "quantitative"},
    "y2": {"field": "bottom"}
  }
}

enter image description here

答案 1 :(得分:0)

另一种类似的方法,将其添加为另一个答案,以方便其他人使用。

axis

select t.*, (case when lag(input, 1, input) over (partition by person_id order by start_date) = input then 0 else 1 end) as FLAG from table t; 属性将轴线移动固定像素,与数据无关。不过,使用offset会在offsetx轴线之间添加一个间隙。

y