Code for Ticks Control with Vegalite.jl

I tried before, searched the Vegalite.jl documentation, searched the original Vegalite documentation (and tried to convert some code), considered somewhat directly using JSON-like code, and didn’t succeed in this matter. I left it alone for a while because it wasn’t so important at the time.

Now it has become important: what is the most direct and easy code example to control ticks with Vegalite.jl?

(Can you also use a range with steps to signify ticks?)
(Is there any plan to expand the existing Vegalite.jl documentation, or even fully translate the original Vegalite documentation?)

Here is an example on how to change some tick aspects:

cars |>
@vlplot(
  :point,
  x={:Miles_per_Gallon, axis={tickSize=50, tickWidth=3, values=[5, 7,34]}},
  y=:Displacement
)

You can get the documentation for the other options here. Let me know if that helps you get started!

I think you should be able to use a julia range as the value for values.

Any help with expanding the documentation would be super welcome. I don’t think I’ll have much time to spend on that in the near future. I also thought whether there might be some way to auto-translate the original documentation and incorporate that into the Julia docs, but never really had enough time to explore that option. I think Altair (the python wrapper for vega-lite) does that, but not sure.

1 Like

Thanks. It certainly helps me get going.

There still seems to be a problem, as I cannot enforce e.g. the X axis ticks beyond the automatically detected visual reach of data. For example, SepalLength in the iris set goes up to 8, but I cannot set the X ticks to reach 10. (I used values = collect(2:10), or just 2:10, which does start the X ticks at 2, but also leaves a big blank space to the left between 2 and the undesired 0.)

The range way with a step also does not work, and totally removes the ticks (in this case on the Y axis).

I think I am not qualified to help you at the moment. I still need to get better at Vegalite.jl.

If you want to change the range of values shown you need to adjust the scale:

cars |> @vlplot(
  :point,
  x={
    :Miles_per_Gallon,
    axis={tickSize=50, tickWidth=3, values=2:10:30},
    scale={domain=[0, 100]}
  },
  y=:Displacement
)

Can you post the code you are using? The range syntax I’m using in the above example seems to work on my system.

This time I took your last example code (and changing ticksize to 5 and tickWidth to 1).

If I use for values a simple array like [0, 40, 80, 100], it works as expected, and these specific values are shown.

If I use a range, like 0:10:100, the X axis shows no ticks at all.

Strange, this code:

cars |> @vlplot(:point, x={:Miles_per_Gallon, axis={values=2:10:100}, scale={domain=[0, 100]}}, y=:Displacement, width=600, background=:white)

produces this plot for me:
foo

which does pick up the range for the axis values… Can you post the exact code you are using?

Thanks for the help.

Yes. I will post it probably today or tomorrow. (Just writing this to let you know I haven’t forgotten you or your request.)

1 Like

Here is the code I used this time:

cars |>
  @vlplot(
    :point,
    x = {
      :Displacement,
      scale = {
        domain = [0, 600]
      },
      axis = {
        tickSize = 5,
        tickWidth = 1,
        values = [0:50:600]
      }
    },
    y = {
      :Miles_per_Gallon,
      title = "MPG"
    },
    width = 300,
    height = 300
  )

Try to use values = 0:50:600 instead of values = [0:50:600].

The expression [0:50:600] creates an array of ranges, which is not what you want to pass here (you can also think of that as an array of arrays). The expression 0:50:600 creates just a range, and any range is a subtype of AbstractArray, so you are passing an array of ticks in that case.

With that change the plot looks good on my system.

1 Like

Ohhh, why didn’t I see that?!