# Plot with four y-axes (, so two y-axis have to be double)

**URL:** <https://discourse.julialang.org/t/plot-with-four-y-axes-so-two-y-axis-have-to-be-double/72985>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [December 12, 2021, 7:28pm UTC](https://discourse.julialang.org/t/plot-with-four-y-axes-so-two-y-axis-have-to-be-double/72985 "2021-12-12T19:28:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dadaforpeace](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@dadaforpeace](https://discourse.julialang.org/u/dadaforpeace)\
**Post date:** [December 12, 2021, 7:28pm UTC](https://discourse.julialang.org/t/plot-with-four-y-axes-so-two-y-axis-have-to-be-double/72985/1 "2021-12-12T19:28:44Z")

</div>

Hi,

I am trying to extend the example found here ([Plot with three y-axes (, so one y-axis has to be double) - #10 by dadaforpeace](https://discourse.julialang.org/t/plot-with-three-y-axes-so-one-y-axis-has-to-be-double/58699/10)) to four y-axes such that two y-axis have to be drawn double. The data and a jupyter notebook file can be found here [https://datashare.mpcdf.mpg.de/s/HHpPb4lqpvfs4Ip](https://datashare.mpcdf.mpg.de/s/HHpPb4lqpvfs4Ip). I arrive with the following code

```julia
using Plots
using CSV
using DataFrames
using Colors

df_1 = DataFrame(CSV.File("Energy.csv"))
df_2 = DataFrame(CSV.File("Population.csv"))
df_3 = DataFrame(CSV.File("Ppm.csv"))
df_4 = DataFrame(CSV.File("gdp-world.csv"))

a=18
plot(df_2.Year,df_2[:,4],
    xlims=(1800,2021),
    label = "Population", 
    ylabel = "World Population",
    color=RGB(0.015, 0.749, 0.678),
    linewidth=3, 
    legend = :topleft, 
    grid = :off,
    size = (1600,800),
    left_margin = 10Plots.mm, 
    right_margin = 50Plots.mm, 
    #background_color=:transparent, 
    foreground_color=:black, 
    foreground_color_guide = RGB(0.015, 0.749, 0.678),
    ytickfontcolor = RGB(0.015, 0.749, 0.678),
    xtickfontsize=a,
    ytickfontsize=a,
    xguidefontsize=a,
    yguidefontsize=a,
    legendfontsize=a)
p = twinx()
plot(p,df_3.Year,df_3[:,4],
    xlims=(1800,2021),
    label = "Global CO₂ atmospheric concentration", 
    ylabel = "\n\n\n\n\n"*"Global CO₂ concentration in ppm",
    color =RGB(0.949, 0.388, 0.388),
    linewidth=3, 
    legend = :topright, 
    grid = :off,
    size = (1600, 800),
    left_margin = 10Plots.mm, 
    right_margin = 50Plots.mm, 
    #background_color=:transparent, 
    foreground_color=:black,
    yticks = [280,315,345,380,410],
    foreground_color_guide = RGB(0.949, 0.388, 0.388),
    ytickfontcolor = RGB(0.949, 0.388, 0.388),
    xtickfontsize=a,
    ytickfontsize=a,
    xguidefontsize=a,
    yguidefontsize=a,
    legendfontsize=a)
p = twinx()
plot!(p,df_4.Year,df_4.GDP,
    xlims=(1800,2021),
    label = "World GDP", 
    ylabel = "World GDP in Dollar",
    color =RGB(0.949, 0.670, 0.152),
    linewidth=3, 
    legend = :bottomright, 
    grid = :off,
    size = (1600, 800),
    left_margin = 10Plots.mm, 
    right_margin = 50Plots.mm, 
    #background_color=:transparent, 
    foreground_color=:black,
    foreground_color_guide = RGB(0.949, 0.670, 0.152),
    ytickfontcolor = RGB(0.949, 0.670, 0.152),
    xtickfontsize=a,
    ytickfontsize=a,
    xguidefontsize=a,
    yguidefontsize=a,
    legendfontsize=a)
p = twinx()
plot!(p,df_1.Year,df_1.sum,
    xlims=(1800,2021),
    label = "Energy Consumption", 
    ylabel = "World Primary Energy Consumption",
    color =RGB(0.949, 0.219, 0.694),
    linewidth=3, 
    legend = :left, 
    grid = :off,
    size = (1600, 800),
    left_margin = 10Plots.mm, 
    right_margin = 50Plots.mm, 
    #background_color=:transparent, 
    foreground_color=:black,
    foreground_color_guide = RGB(0.949, 0.219, 0.694),
    ytickfontcolor = RGB(0.949, 0.219, 0.694),
    xtickfontsize=a,
    ytickfontsize=a,
    xguidefontsize=a,
    yguidefontsize=a,
    legendfontsize=a)

```

already to a result that shows the four axes but is unfortunately not 100% satisfying.

 ![Population-Energy-PPM-GDP](https://global.discourse-cdn.com/julialang/original/3X/f/6/f6033dc2fe2e61c67395923fe01e7e11092b31b1.png)

I have the following questions:

1. How can I move the GDP axis to the left side.
2. How can I group the four legends such that they are aligned in the top left corner going from the top down to the middle in ascending size down?
3. How can I change the numbers into a readable format, i.e. 2.0x10^9 to 2 Billion.

Thank you very much in advance =)
