# Vegalite bar chart strange behaviour

**URL:** <https://discourse.julialang.org/t/vegalite-bar-chart-strange-behaviour/104261>\
**Category:** Visualization\
**Created:** [September 26, 2023, 1:30pm UTC](https://discourse.julialang.org/t/vegalite-bar-chart-strange-behaviour/104261 "2023-09-26T13:30:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Axze-rgb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/axze-rgb/32/50986_2.png) [@Axze-rgb](https://discourse.julialang.org/u/Axze-rgb)\
**Post date:** [September 26, 2023, 1:30pm UTC](https://discourse.julialang.org/t/vegalite-bar-chart-strange-behaviour/104261/1 "2023-09-26T13:30:55Z")

</div>

Hello, I have a dataframe of a single column, it contains 619245 data points. I want to make a bar char to check the distribution. Here is my code

> df\_BQBZ|\>  
> @vlplot(:bar, height=250, width=500, x={:BQBZ, steps=0.3}, y=“count()”)

And here is the resulting plot. Something is off, if you look at the number on the y axis, I should be in the range hundred of thousands, but it shows 1600. Also, this code causes regular crashes of Pluto. I have 24 threads and 70 Go of ram so it shouldn’t be a hardware issue.

![weird](https://global.discourse-cdn.com/julialang/original/3X/c/d/cd3f68b2b01505d8fafce6507a4ca1f1d95f9056.png)

can someone help me debug my plot?  
Thank you

---

<div class="post-metadata">

**Author:** ![devel-chm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/devel-chm/32/3572_2.png) [@devel-chm](https://discourse.julialang.org/u/devel-chm)\
**Post date:** [September 26, 2023, 1:35pm UTC](https://discourse.julialang.org/t/vegalite-bar-chart-strange-behaviour/104261/2 "2023-09-26T13:35:36Z")

</div>

Maybe try with a subset of the data to see if it is correct for differing  
counts of input values?

---

<div class="post-metadata">

**Author:** ![Axze-rgb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/axze-rgb/32/50986_2.png) [@Axze-rgb](https://discourse.julialang.org/u/Axze-rgb)\
**Post date:** [September 26, 2023, 2:09pm UTC](https://discourse.julialang.org/t/vegalite-bar-chart-strange-behaviour/104261/3 "2023-09-26T14:09:28Z")

</div>

It’s actually working, the first time it produced this correct plot, and now I don’t know why I can’t reproduce it  
 ![visualization](https://global.discourse-cdn.com/julialang/original/3X/9/d/9d58347c56fd3441bf8639ba30a74b4cba7a4f3e.png)

---

<div class="post-metadata">

**Author:** ![Axze-rgb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/axze-rgb/32/50986_2.png) [@Axze-rgb](https://discourse.julialang.org/u/Axze-rgb)\
**Post date:** [September 26, 2023, 2:18pm UTC](https://discourse.julialang.org/t/vegalite-bar-chart-strange-behaviour/104261/4 "2023-09-26T14:18:33Z")

</div>

Ok, I can reproduce the correct plot with this simple code

> df\_BQBZ|\>  
> @vlplot(  
> :bar,  
> x={:BQBZ,bin=true},  
> y=:“count()”  
> )

But as soon as I try to change the “step” values I get the plot of the original message. Any idea? I would love steps of 0.2

I ended up making a density plot, because I need to progress

> df\_BQBZ|\>  
> @vlplot(  
> :area,  
> transform=[  
> {density=“BQBZ”,bandwidth=0.2}  
> ],  
> x={“value:q”, title=“BGBZ values”},  
> y=“density:q”  
> )

but I still would love how to change the step of the binning in the histogram

---

<div class="post-metadata">

**Author:** ![devel-chm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/devel-chm/32/3572_2.png) [@devel-chm](https://discourse.julialang.org/u/devel-chm)\
**Post date:** [September 26, 2023, 3:32pm UTC](https://discourse.julialang.org/t/vegalite-bar-chart-strange-behaviour/104261/6 "2023-09-26T15:32:11Z")

</div>

[the vega-lite bin docs](https://vega.github.io/vega-lite/docs/bin.html) shows the various ways to set the binning parameters.

The [VegaLite Tutorial](https://www.queryverse.org/VegaLite.jl/stable/gettingstarted/tutorial/#Next-steps-1) has an example using the `Vega.printrepr()` function to generate the `@vlplot` style version of a JSON specification as from the vega-lite site.

---

<div class="post-metadata">

**Author:** ![brucala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brucala/32/14229_2.png) [@brucala](https://discourse.julialang.org/u/brucala)\
**Post date:** [September 26, 2023, 7:55pm UTC](https://discourse.julialang.org/t/vegalite-bar-chart-strange-behaviour/104261/7 "2023-09-26T19:55:48Z")

</div>

As mentioned by @devel-chm, the vega-lite docs have a detailed documentation to customize the binning. In particular, if you want to fix the bin width, you can do it with the `step` property of the [bin parameters](https://vega.github.io/vega-lite/docs/bin.html#bin-parameters).

In VegaLite.jl probably you need to do `x={:BQBZ, bin={step=0.2}}.`

In [Deneb.jl](https://github.com/brucala/Deneb.jl), you can have a look at [this example](https://brucala.github.io/Deneb.jl/dev/examples/single_view_plots/histograms/histogram_with_fine_binning/#Histogram-with-fine-binning) and replace `maxbins=50` with `step=0.2`.

As for the crashes in Pluto. Is your `df_BQBZ` dataset very large? VegaLite charts store the whole data in its specification, so several plots with fairly large data can easily result in slow responsiveness (and possibly crashes?). You can see more about that in [Altair’s documentation](https://altair-viz.github.io/user_guide/large_datasets.html#challenges). A common approach to solve that is to pre-aggregate the data (e.g. binning) and filter it to keep only the columns that the figure needs.

---

<div class="post-metadata">

**Author:** ![Axze-rgb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/axze-rgb/32/50986_2.png) [@Axze-rgb](https://discourse.julialang.org/u/Axze-rgb)\
**Post date:** [September 26, 2023, 8:07pm UTC](https://discourse.julialang.org/t/vegalite-bar-chart-strange-behaviour/104261/8 "2023-09-26T20:07:02Z")

</div>

Thanks, your solution works beautifully. I still sometimes have issues with the Julia syntax. I am not coming from an IT background. The data sets are relatively large. We are in a million data points. I switched to a Jupyter notebook, and there was no problem.

Thank you for mentioning Deneb.jl I did not know about it.
