# Code for Ticks Control with Vegalite.jl

**URL:** <https://discourse.julialang.org/t/code-for-ticks-control-with-vegalite-jl/31134>\
**Category:** Visualization\
**Tags:** question, package, plotting\
**Created:** [November 15, 2019, 5:11pm UTC](https://discourse.julialang.org/t/code-for-ticks-control-with-vegalite-jl/31134 "2019-11-15T17:11:09Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Usor](https://avatars.discourse-cdn.com/v4/letter/u/8dc957/32.png) [@Usor](https://discourse.julialang.org/u/Usor)\
**Post date:** [November 15, 2019, 5:11pm UTC](https://discourse.julialang.org/t/code-for-ticks-control-with-vegalite-jl/31134/1 "2019-11-15T17:11:09Z")

</div>

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?)

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [November 15, 2019, 7:40pm UTC](https://discourse.julialang.org/t/code-for-ticks-control-with-vegalite-jl/31134/2 "2019-11-15T19:40:05Z")

</div>

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

```julia
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](https://vega.github.io/vega-lite/docs/axis.html#ticks). 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.

---

<div class="post-metadata">

**Author:** ![Usor](https://avatars.discourse-cdn.com/v4/letter/u/8dc957/32.png) [@Usor](https://discourse.julialang.org/u/Usor)\
**Post date:** [November 15, 2019, 8:24pm UTC](https://discourse.julialang.org/t/code-for-ticks-control-with-vegalite-jl/31134/3 "2019-11-15T20:24:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [November 15, 2019, 9:11pm UTC](https://discourse.julialang.org/t/code-for-ticks-control-with-vegalite-jl/31134/4 "2019-11-15T21:11:21Z")

</div>

If you want to change the range of values shown you need to adjust the [scale](https://vega.github.io/vega-lite/docs/scale.html#domain):

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

```

> [@Usor](#):
>
> The range way with a step also does not work, and totally removes the ticks (in this case on the Y axis).

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

---

<div class="post-metadata">

**Author:** ![Usor](https://avatars.discourse-cdn.com/v4/letter/u/8dc957/32.png) [@Usor](https://discourse.julialang.org/u/Usor)\
**Post date:** [November 15, 2019, 9:45pm UTC](https://discourse.julialang.org/t/code-for-ticks-control-with-vegalite-jl/31134/5 "2019-11-15T21:45:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [November 15, 2019, 10:19pm UTC](https://discourse.julialang.org/t/code-for-ticks-control-with-vegalite-jl/31134/6 "2019-11-15T22:19:01Z")

</div>

Strange, this code:

```julia
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](https://global.discourse-cdn.com/julialang/original/3X/4/1/41684f48ec92fc240b11b8088fc7312e7b945d46.png)

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

---

<div class="post-metadata">

**Author:** ![Usor](https://avatars.discourse-cdn.com/v4/letter/u/8dc957/32.png) [@Usor](https://discourse.julialang.org/u/Usor)\
**Post date:** [November 16, 2019, 9:56pm UTC](https://discourse.julialang.org/t/code-for-ticks-control-with-vegalite-jl/31134/7 "2019-11-16T21:56:40Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![Usor](https://avatars.discourse-cdn.com/v4/letter/u/8dc957/32.png) [@Usor](https://discourse.julialang.org/u/Usor)\
**Post date:** [November 17, 2019, 5:22pm UTC](https://discourse.julialang.org/t/code-for-ticks-control-with-vegalite-jl/31134/8 "2019-11-17T17:22:12Z")

</div>

Here is the code I used this time:

```julia
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
  )

```

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [November 18, 2019, 9:26pm UTC](https://discourse.julialang.org/t/code-for-ticks-control-with-vegalite-jl/31134/9 "2019-11-18T21:26:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Usor](https://avatars.discourse-cdn.com/v4/letter/u/8dc957/32.png) [@Usor](https://discourse.julialang.org/u/Usor)\
**Post date:** [November 20, 2019, 1:01pm UTC](https://discourse.julialang.org/t/code-for-ticks-control-with-vegalite-jl/31134/10 "2019-11-20T13:01:08Z")

</div>

Ohhh, why didn’t I see that?!
