Deneb - "Inside Base" Label Position

I’m trying to re-create some charts I have in an existing report using Deneb, and one of the things I’m struggling with is how to replicate the “inside base” data label positioning. Using the simple bar chart example below, how would I position the text mark inside the base of the bars?

sample bar chart

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "values": [
      {"a": "A", "b": 28},
      {"a": "B", "b": 55},
      {"a": "C", "b": 33},
      {"a": "D", "b": 91},
      {"a": "E", "b": 81},
      {"a": "F", "b": 53},
      {"a": "G", "b": 19},
      {"a": "H", "b": 87},
      {"a": "I", "b": 52}
    ]
  },
  "encoding": {
    "x": {
      "field": "a",
      "type": "nominal"
    },
    "y": {
      "field": "b",
      "type": "quantitative"
    }
  },
  "layer": [
    {
      "mark": "bar"
    },
    {
      "mark": {
        "type": "text",
        "align": "center",
        "dy": -8
      },
      "encoding": {
        "text": {
          "field": "b", 
          "type": "quantitative"
        }
      }
    }
  ]
}

Hi @DaveC. There are probably a number of ways to do this in Deneb/Vega-Lite; a simple one is to add an axis block to the x-axis block, as:

Hope this helps.
Greg
eDNA Forum - X-axis Label Inside Bar Base.pbix (1.3 MB)

@Greg, that’s a helpful example to have in my pocket for other applications. For this specific application, what I need to show in the base of the bars is the value associated with each bar (as opposed to the axis label). So, instead of showing 28, 55, 33, etc. above each bar, I need those values to show inside the base of the bar in the exact position where you put the axis labels in your example. Hope that makes sense.

Hi @DaveC … OK, different question. In that case, delete the axis block and instead use a layer block with the bar mark as-is and a text mark with the value at a fixed Y location (e.g., “y”: {“datum”: 2 } (I don’t have time right now to check, but I think this is right.)
Hope this helps.
Greg

1 Like

That did the trick! Thanks!