# VegaLite Line Plot Question

**URL:** <https://discourse.julialang.org/t/vegalite-line-plot-question/73562>\
**Category:** New to Julia\
**Tags:** vegalite\
**Created:** [December 23, 2021, 11:49pm UTC](https://discourse.julialang.org/t/vegalite-line-plot-question/73562 "2021-12-23T23:49:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbjulia](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dbjulia](https://discourse.julialang.org/u/dbjulia)\
**Post date:** [December 23, 2021, 11:49pm UTC](https://discourse.julialang.org/t/vegalite-line-plot-question/73562/1 "2021-12-23T23:49:01Z")

</div>

I am trying to using VegaLite for a simple line plot. However, when I try and have the x-axis sort how the dataframe is sorted vs the default sort done Vegalite the line plot goes haywire. See below code and example can someone help with this problem.

Org Plot and Code, notice the x-axis is note sorted in date order.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/9/c97205dd222e9e15343a9379561935f88977d948.png)

Now the below image is when settings the sort to null. In order to get the x-axis in date order. ]

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/0/d0a9414a3b369690d046b67e74852e4f939c6128.png)

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [December 24, 2021, 9:05am UTC](https://discourse.julialang.org/t/vegalite-line-plot-question/73562/2 "2021-12-24T09:05:31Z")

</div>

The sort parameter expects an array:

```julia
julia> using VegaLite, DataFrames
julia> Summ_USCovid=DataFrame(:Month_Year => ["Apr 2020","May 2020","Apr 2021","May 2021"],:TotalCases => [100000.0,200000.0,400000,500000])
4×2 DataFrame
 Row │ Month_Year TotalCases
     │ String Float64
─────┼────────────────────────
   1 │ Apr 2020 100000.0
   2 │ May 2020 200000.0
   3 │ Apr 2021 400000.0
   4 │ May 2021 500000.0

julia> Summ_USCovid |> @vlplot(:line,x={:Month_Year,sort=["null"]},y=:TotalCases)

```

How did I found out?  
The documentaion [Sorting | Vega-Lite](https://vega.github.io/vega-lite/docs/sort.html) isn’t so helpfull in this case.  
I don’t know if it is visible in a notebook (like in your screenshots) but when the VegaLite output is opened from a plain julia REPL just in a browser you can see “…” on top right:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/7/97f09805496d90af760eacb1eda1c85587ebaedb.png)

There you can open the Vega Editor:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/4/a45b62da0a645c7aa29cb69b8cda0cb7127f9ca2.png)

There the LOG is helping to find out what may be wrong.

---

<div class="post-metadata">

**Author:** ![dbjulia](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dbjulia](https://discourse.julialang.org/u/dbjulia)\
**Post date:** [December 24, 2021, 3:52pm UTC](https://discourse.julialang.org/t/vegalite-line-plot-question/73562/3 "2021-12-24T15:52:23Z")

</div>

Thanks @oheil you are correct it is looking for an array, so when I provided an empty one it goes to the sort provided in the dataframe. I have the code and result below to demonstrate the correct results. Also, thanks for showing me how to troubleshoot in the future.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/9/994bb8576cc5a79463e721368f732922e9347598.png)
