How do I add a secondary Y axis to my vega-lite chart?

北战南征 提交于 2019-12-01 03:53:16

问题


This question shows a way to add multiple time series to a vega-lite chart:

How to plot several variables on an axis with Vega-Lite?

Is there a way to put the second series on the secondary Y axis? I'm talking about putting another Y axis on the right hand side so that the time series can have different scales but still be compared.

The following image demonstrates the kind of chart that I'm after:

Here is an example chart, please show me how to move the second time series to a new Y axis on the right of the chart:

https://vega.github.io/editor/#/gist/vega-lite/ashleydavis/3dbd3b83f2a67da8fe20ef444fd4958e

Update:

I have partially solved my problem, but not 100%.

By adding "axis" and "orient" fields to my vega-lite chart I've been been able to move the second series to the right hand side as you can see here:

https://vega.github.io/editor/#/gist/vega-lite/ashleydavis/5aea58ee98c2eec9913b309836181a5b

The problem I'm having now is that the when I try to create a chart like this with two different time series with values on completely different scales I get something that isn't useful.

You can see from this chart that both sides of the chart use the same scale and this makes it impossible to compare the data because the first series (which is on a smaller scale) ends up being completely squashed.

You can see the chart from the screenshot here:

https://vega.github.io/editor/#/gist/vega-lite/ashleydavis/af1958d3f22bd876959ebcc97105dd14

So the question now is how do I make these axis' independent so the data is overlaid and easily comparable?

(Not that it makes sense to compare the data in this example, but generally I need to be able to do this).


回答1:


Yes, you can set axes and scales to be independent with the resolve property. Vega-Lite will automatically create two axes for you.

See https://vega.github.io/vega-lite/docs/layer.html#combined-scales-and-guides.



来源:https://stackoverflow.com/questions/45610630/how-do-i-add-a-secondary-y-axis-to-my-vega-lite-chart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!