# VegaLite vlplot basic usage, encoding

**URL:** <https://discourse.julialang.org/t/vegalite-vlplot-basic-usage-encoding/57700>\
**Category:** Visualization\
**Tags:** question, plotting, vegalite\
**Created:** [March 22, 2021, 11:04am UTC](https://discourse.julialang.org/t/vegalite-vlplot-basic-usage-encoding/57700 "2021-03-22T11:04:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [March 22, 2021, 11:04am UTC](https://discourse.julialang.org/t/vegalite-vlplot-basic-usage-encoding/57700/1 "2021-03-22T11:04:06Z")

</div>

I’m new to both Vega Lite and VegaLite.jl, and I’m confused about exactly how is `vlplot` supposed to work. The VegaLite documentation seems to consist mostly of examples and lacks a more systematic approach to documentation, so I’m having a hard time figuring out the thing that’s confusing me here. (The `@vlplot` macro is confusing me even more than `vlplot`, because it doesn’t use Julia syntax, so I would prefer not to use it.)

This is the [first example](https://vega.github.io/vega-lite/docs/point.html#dot-plot) for the “Point” Vega Lite “mark” in the docs, it plots a dot plot:

```julia
{
  "data": {"url": "data/movies.json"},
  "mark": "point",
  "encoding": {
    "x": {"field": "IMDB Rating", "type": "quantitative"}
  }
}

```

This is my initial snippet, basically an attempt at a straightforward adaptation of the dot plot example from Vega Lite to `vlplot`:

```julia
using IndexedTables, VegaLite
data = Float64[3.3, 3.4, 3.41, 3.9]
tab = table((index = (1:length(data)), values = data), pkey=:index, presorted=true)
pl = vlplot(data = tab, mark = :point, encoding = (x = (field = :values, type = :quantitative)))

```

The above produces just a _ **single dot** _ instead of dot plot, even though it seems like it should “naturally” work. But the below correction works as expected:

```julia
pl = vlplot(data = tab, mark = :point, x = (field = :values, type = :quantitative))

```

From this I would conclude that a Vega Lite encoding has to be specified “inline” in VegaLite.jl, **except** that the VegaLite documentation actually has some examples where `@vlplot` is given an `encoding` argument just like here. (E.g., here: [The @vlplot command · VegaLite.jl](https://www.queryverse.org/VegaLite.jl/stable/userguide/vlplotmacro/#Shorthand-string-syntax-for-encodings-1))

So I don’t really get what’s wrong with my initial example. Can somebody help me understand?

---

<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:** [March 22, 2021, 7:01pm UTC](https://discourse.julialang.org/t/vegalite-vlplot-basic-usage-encoding/57700/2 "2021-03-22T19:01:27Z")

</div>

Your assumption that function `vlplot` can just be used instead of macro `@vlplot` is wrong. The docs [Home · VegaLite.jl](https://www.queryverse.org/VegaLite.jl/stable/) don’t mention the function at all, so it’s clearly recommended to use the macro.  
With that translation is straightforward, at least for this simple example:

```julia
pl = @vlplot(
	data = tab, 
	mark = :point, 
	encoding = {
		x = {
			field = :values, 
			type = :quantitative
		}
	}
)

```
