VegaLite Line Plot Question

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.

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

The sort parameter expects an array:

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

There you can open the Vega Editor:

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

1 Like

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.

1 Like