Average line is not shown as expected in vega visualization

{

  "$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

  "$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

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?

{
  "$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

this is the solution

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