简体   繁体   English

如何在 vega-lite 的折线图中画一条线?

[英]How to draw a line in a line chart in vega-lite?

I have a curve plotted from index我有一条从索引绘制的曲线

{
  "$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", "type": "quantitative", "title":"True Positive Rate"}
  }
}

the plot looks like plot 看起来像在此处输入图像描述

Now i need to draw a base line for base model between 0 and 1 like现在我需要在 0 和 1 之间为基本 model 画一条基线,例如在此处输入图像描述

Is this possible, and make that as dashed line with legend showing names as Base Model, RF Model这可能吗,并将其设为带有图例的虚线,显示名称为 Base Model, RF Model

Yes, it is possible using Layered Views .是的,可以使用分层视图

I'll use the Line Chart example to modify and add another line that's also dashed.我将使用折线图示例来修改和添加另一条虚线。 Original chart: https://vega.github.io/editor/#/examples/vega-lite/line原图: https://vega.github.io/editor/#/examples/vega-lite/line

Here's the modified chart, I used explicit values for the straight line:这是修改后的图表,我对直线使用了明确的值:

在此处输入图像描述

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

Layer Solution层解决方案

When you use layered view, you can lay multiple lines in the same chart and same x and y axis当您使用分层视图时,您可以在同一个图表和相同的 x 和 y 轴中放置多条线

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

Dashed Line虚线

Can be achieved using strokeDash property.可以使用strokeDash属性来实现。 See this example: Line chart with varying stroke dash请参阅此示例: 具有不同笔划破折号的折线图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM