Help with range plot with VegaLite.jl

I’m having trouble creating a range plot with VegaLite.jl (similar to this How to create a range plot - Datawrapper Academy, but with the ranges orientated vertically). I just need a simple line connecting ul to ll for each value of m, but I can’t even plot both ul and ll in the same “canvas”.

using DataFrames
using VegaLite

df = DataFrame(m = 1:5, ll=21:25, ul=:31:35)

df |> @vlplot(
    height=400,
    width=400,
    :point,
    x=:m,
    y=:ul
) +
@vlplot(
    height=400,
    width=400,
    :point,
    x=:m,
    y=:ll
)

The online documentation shows some examples where they calculate ul and ll from raw data, as opposed to the “summarized” example I present here.

I think this should do the trick:

df |> @vlplot(x=:m, height=400, width=400) +
  @vlplot(:point, y=:ul) +
  @vlplot(:point, y=:ll) +
  @vlplot(:rule, y=:ul, y2=:ll)

I pulled the common properties for all layers into a first call to @vlplot that doesn’t have any mark. So this first call does not turn into a layer, this becomes the “parent” spec.

1 Like

I am now trying to add a horizontal line at y=25, but this doesn’t render it

df |> @vlplot(x=:m, height=400, width=400) +
  @vlplot(:point, y=:ul) +
  @vlplot(:point, y=:ll) +
  @vlplot(:rule, y=:ul, y2=:ll) +
  @vlplot(:rule, data={values=[{}]}, y={datum=13.22, type="quantitative"})