# How to use strings to specify plot axes in VegaLite.jl?

**URL:** <https://discourse.julialang.org/t/how-to-use-strings-to-specify-plot-axes-in-vegalite-jl/67405>\
**Category:** Visualization\
**Tags:** plotting, vegalite\
**Created:** [August 31, 2021, 6:30am UTC](https://discourse.julialang.org/t/how-to-use-strings-to-specify-plot-axes-in-vegalite-jl/67405 "2021-08-31T06:30:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)\
**Post date:** [August 31, 2021, 6:30am UTC](https://discourse.julialang.org/t/how-to-use-strings-to-specify-plot-axes-in-vegalite-jl/67405/1 "2021-08-31T06:30:12Z")

</div>

How can I use strings to call columns of a `DataFrame` in `VegaLite.jl`?

```julia
using DataFrames
using VegaLite

df = DataFrame("x" => 1:5, "y.α" => 1:5)
df |> @vlplot(
    :line, x = "x", y = "y.α"
)

ERROR: LoadError: ArgumentError: Invalid shortcut string

```

---

<div class="post-metadata">

**Author:** ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)\
**Post date:** [August 31, 2021, 6:44am UTC](https://discourse.julialang.org/t/how-to-use-strings-to-specify-plot-axes-in-vegalite-jl/67405/2 "2021-08-31T06:44:03Z")

</div>

Doesn’t happen if the `DataFrame` column names do not contain the period:

```julia
df = DataFrame("x" => 1:5, "y" => 1:5)
df |> @vlplot(
    :line, x = "x", y = "y"
)

```

---

<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:** [August 31, 2021, 7:57am UTC](https://discourse.julialang.org/t/how-to-use-strings-to-specify-plot-axes-in-vegalite-jl/67405/3 "2021-08-31T07:57:40Z")

</div>

There is a related issue:

> <https://github.com/queryverse/VegaLite.jl/issues/285>
>
> When using a type that implements the TableIterators interface, it seems that co…lumns with brackets in their names, though valid symbols, are not processed correctly. While the column names are correctly assigned to their axes, none of the data is plotted. A minimal example:
> 
> \`\`\`julia
> julia\> using VegaLite, DataFrames
> 
> julia\> df = DataFrames.DataFrame(\[1:5, 6:10, 11:15\], \[:var1, :var2, Symbol("var\[3\]")\])
> 5×3 DataFrame
> │ Row │ var1 │ var2 │ var\[3\] │
> │ │ Int64 │ Int64 │ Int64 │
> ├─────┼───────┼───────┼────────┤
> │ 1 │ 1 │ 6 │ 11 │
> │ 2 │ 2 │ 7 │ 12 │
> │ 3 │ 3 │ 8 │ 13 │
> │ 4 │ 4 │ 9 │ 14 │
> │ 5 │ 5 │ 10 │ 15 │
> 
> julia\> @vlplot(:point, data=df, x=:var1, y=:var2)
> \`\`\`
> \<img width="244" alt="Screen Shot 2020-03-21 at 11 13 55 PM" src="https://user-images.githubusercontent.com/8673634/77243656-cf601300-6bc9-11ea-9832-2a68942d3a63.png"\>
> 
> \`\`\`julia
> julia\> @vlplot(:point, data=df, x=:var1, y=Symbol("var\[3\]"))
> \`\`\`
> \<img width="223" alt="Screen Shot 2020-03-21 at 11 14 16 PM" src="https://user-images.githubusercontent.com/8673634/77243658-d71fb780-6bc9-11ea-8f05-673ba0ebf094.png"\>

As described here

> **[Encoding](https://vega.github.io/vega-lite/docs/encoding.html#field-def)**
>
> Vega-Lite - a high-level grammar for statistical graphics. Vega-Lite provides a higher-level grammar for visual analysis, comparable to ggplot or Tableau, that generates complete Vega specifications. Vega-Lite specifications consist of simple...

> **Notes:** 1) Dots ( `.` ) and brackets ( `[` and `]` ) can be used to access nested objects … you can use `\\` to escape dots and brackets …

Escaping doesn’t work.  
I added this thread to the issue as related.
