如何在Vega-Lite中绘制折线图中的线?

问题描述

我从索引上画了一条曲线

{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.4.json","title": {
    "text": "Receiver Operating Characteristics - Area Under Curve","anchor": "middle","fontSize": 16,"frame": "group","offset": 4
  },"data": {
    "url" : {
        "%context%": true,"index": "roccurve_index2","body": {
          "size":10000,"_source": ["lr_fpr","lr_tpr"],}
      }  
      "format": {"property": "hits.hits"},},"mark": {
    "type": "line","point": true
  },"encoding": {
    "x": {"field": "_source.lr_fpr","type": "quantitative","title":"False Positive Rate"},"y": {"field": "_source.lr_tpr","title":"True Positive Rate"}
  }
}

情节看起来像

enter image description here

现在我需要为基本模型绘制一条介于0和1之间的基线

enter image description here

这是可能的,并使其成为带有图例的虚线,并显示名称为“基本模型”,“ RF模型”

解决方法

是的,可以使用Layered Views

我将使用Line Chart example来修改并添加另一条也用虚线表示的行。 原始图表: https://vega.github.io/editor/#/examples/vega-lite/line

这是修改后的图表,我为直线使用了明确的值:

enter image description here

https://vega.github.io/editor/#/gist/152fbe5f986ba78e422bb3430628f010/spec.json

层解决方案

使用分层视图时,可以在同一图表中以及同一x和y轴上放置多条线

  "layer" : [
      {
         //mark #1
      },{
        //mark #2
      }
  ]

虚线

可以使用strokeDash属性来实现。请参见以下示例:Line chart with varying stroke dash

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...