# Average line is not shown as expected in vega visualization

**URL:** <https://discuss.elastic.co/t/average-line-is-not-shown-as-expected-in-vega-visualization/258314>\
**Category:** Kibana\
**Created:** [December 10, 2020, 5:49pm UTC](https://discuss.elastic.co/t/average-line-is-not-shown-as-expected-in-vega-visualization/258314 "2020-12-10T17:49:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pranusha119](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@Pranusha119](https://discuss.elastic.co/u/Pranusha119)\
**Post date:** [December 10, 2020, 5:49pm UTC](https://discuss.elastic.co/t/average-line-is-not-shown-as-expected-in-vega-visualization/258314/1 "2020-12-10T17:49:30Z")

</div>

```auto
{

  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",

  "description": "Bar chart with text labels. Apply scale padding to make the frame cover the labels.",

  "data": {

    "values": [

      {"a": "A", "b": 28},

      {"a": "B", "b": 55},

      {"a": "C", "b": 43}

    ]

  },

  "encoding": {

    "y": {"field": "a", "type": "nominal"},

    "x": {"field": "b", "type": "quantitative", "scale": {"padding": 10}}

  },

  "layer": [{

    "mark": "bar"

  }, {

    "mark": {

      "type": "text",

      "align": "left",

      "baseline": "middle",

      "dx": 3

    },

    "encoding": {

      "text": {"field": "b", "type": "quantitative"}

    }

  }]

}

```

output -

![image](https://us1.discourse-cdn.com/elastic/original/3X/a/a/aa9d20f39aeddf35a21fd94c9a579dd16deaaa91.png)

```auto
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "description": "Bar chart with text labels. Apply scale padding to make the frame cover the labels.",
  "data": {
    "values": [
      {"a": "A", "b": 28},
      {"a": "B", "b": 55},
      {"a": "C", "b": 43}
    ]
  },
  "encoding": {
    "y": {"field": "a", "type": "nominal"},
    "x": {"field": "b", "type": "quantitative", "scale": {"padding": 10}}
  },
  "layer": [{
    "mark": "bar"
  }, {
    "mark": {
      "type": "text",
      "align": "left",
      "baseline": "middle",
      "dx": 3
    },
    "encoding": {
      "text": {"field": "b", "type": "quantitative"}
    }
  },
  {
      "mark": {"type": "rule", "color": "red"},
      "encoding": {
        "x": {
          "aggregate": "average",
          "field": "b",
          "type": "quantitative"
        }
      }
    }]
}

```

output -  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/f/7f6ad63f03e94f0918de226310e6e4fff9343ee9.png)

Here I just want a single vertical line for average, due to encoding of x and y above layer(for getting text) I am getting horizontal lines

Is there any way where I can get vertical average line as well as text for bars?

---

<div class="post-metadata">

**Author:** ![Pranusha119](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@Pranusha119](https://discuss.elastic.co/u/Pranusha119)\
**Post date:** [December 10, 2020, 6:11pm UTC](https://discuss.elastic.co/t/average-line-is-not-shown-as-expected-in-vega-visualization/258314/2 "2020-12-10T18:11:47Z")

</div>

```auto
{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "description": "Bar chart with text labels. Apply scale padding to make the frame cover the labels.",
  "data": {
    "values": [
      {"a": "A", "b": 28},
      {"a": "B", "b": 55},
      {"a": "C", "b": 43}
    ]
  },
  "layer":[  
    {
   "encoding": {
    "y": {"field": "a", "type": "nominal"},
    "x": {"field": "b", "type": "quantitative", "scale": {"padding": 10}}
  },
  "layer": [
  
   {
    "mark": "bar"
  }, {
    "mark": {
      "type": "text",
      "align": "left",
      "baseline": "middle",
      "dx": 3
    },
    "encoding": {
      "text": {"field": "b", "type": "quantitative"}
    }
  }
    ]
    },
    {
      "mark": {"type": "rule", "color": "red"},
      "encoding": {
        "x": {
          "aggregate": "average",
          "field": "b",
          "type": "quantitative"
        }
      }
    }
  ]
}

```

![image](https://us1.discourse-cdn.com/elastic/original/3X/4/9/49026b94933d1cdb56ccaf10a82b5d4fd57e2f12.png)

this is the solution

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 7, 2021, 6:12pm UTC](https://discuss.elastic.co/t/average-line-is-not-shown-as-expected-in-vega-visualization/258314/3 "2021-01-07T18:12:09Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
