# Two y-axes in AoG/Makie?

**URL:** <https://discourse.julialang.org/t/two-y-axes-in-aog-makie/73780>\
**Category:** General Usage\
**Tags:** plotting, makie, algebraofgraphics, vegalite\
**Created:** [December 29, 2021, 7:42pm UTC](https://discourse.julialang.org/t/two-y-axes-in-aog-makie/73780 "2021-12-29T19:42:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)\
**Post date:** [December 29, 2021, 7:42pm UTC](https://discourse.julialang.org/t/two-y-axes-in-aog-makie/73780/1 "2021-12-29T19:42:28Z")

</div>

How can create a plot with two y-axes using AoG / Makie? I want to have two “marks” / geometries with different y-axes. Here is an example using VegaLite.jl.

 ![current](https://global.discourse-cdn.com/julialang/original/3X/d/7/d75be49c5d5662247741a6cb33e29f2e4720c61a.png)

```julia
plt =
    @vlplot(
        data = data0,
            mark = {
                :errorband,
                cornerRadiusTopLeft = 3,
                cornerRadiusTopRight = 3,
                color = "#004c97",
        x = {
            "Year:o",
            axis = {
                title = "Year",
                labelAlign = "center",
                labelAngle = 0,
                titleFontSize = 30,
                labelFontSize = 20,
                dx = 200,
                }},
        height = 800,
        width = 800,
        resolve = {scale = {y = "independent"},
           },
        y = {
            "investment",
            axis = {
                title = "Current Dollars (\$B)",
                titleFontSize = 30,
                labelFontSize = 20,
                titlePadding = 10,
                }},
	    y2 = {"ub"},
        ) +
    @vlplot(
        data = data1,
        mark = {
            :bar,
            cornerRadiusTopLeft = 3,
            cornerRadiusTopRight = 3,
            fillOpacity = 0.25,
            color = "#d86018",
            },
        y = {
            "value",
            axis = {
                title = "Growth Rate (%)",
                titleFontSize = 30,
                labelFontSize = 20,
                titlePadding = 10,
                },
            stack = nothing,
            color = :variable,
            },
    )

```

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [December 29, 2021, 8:26pm UTC](https://discourse.julialang.org/t/two-y-axes-in-aog-makie/73780/2 "2021-12-29T20:26:43Z")

</div>

Dual axes are generally opposed by the grammar of graphics philosophy because they break the one-to-one correspondence between visual space and data space.

Further, dual axis plots seem to relate quantities that aren’t related: one of the most salient features of a plot is where two elements intersect visually, but in dual-axis plots there is no meaningful substantive interpretation of this feature.

It is considered better to have stacked plots sharing an x axis.

---

<div class="post-metadata">

**Author:** ![Jakob](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@Jakob](https://discourse.julialang.org/u/Jakob)\
**Post date:** [December 29, 2021, 10:32pm UTC](https://discourse.julialang.org/t/two-y-axes-in-aog-makie/73780/3 "2021-12-29T22:32:56Z")

</div>

See the section on twin axes in the Makie axis documentation, which contains this example:

```julia
using CairoMakie

f = Figure()

ax1 = Axis(f[1, 1], yticklabelcolor = :blue)
ax2 = Axis(f[1, 1], yticklabelcolor = :red, yaxisposition = :right)
hidespines!(ax2)
hidexdecorations!(ax2)

lines!(ax1, 0..10, sin, color = :blue)
lines!(ax2, 0..10, x -> 100 * cos(x), color = :red)

f

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [December 29, 2021, 10:46pm UTC](https://discourse.julialang.org/t/two-y-axes-in-aog-makie/73780/4 "2021-12-29T22:46:23Z")

</div>

@jzr, one notable exception to your good advice is when we want to have dual axis for one data series displaying different scale units (e.g.: `km/h` and `mph`)
