Plot with three y-axes (, so one y-axis has to be double)

I came up with a satisfying solution myself, after finally finding a solution to move the y-axis label here In Plots.jl, how does one control the space between ylabel and yaxis? - #15 by Andre_Mello. The only thing which I could not solve are the position of the legends. Here is the picture:

And here the corresponding code:

a=18
plot(df_2.Year,df_2[:,4],
    xlims=(1800,2021),
    label = "Population", 
    ylabel = "World Population",
    color=RGB(0.337, 0.631, 0.749),
    linewidth=3, 
    legend = :topleft, 
    grid = :off,
    size = (1600,800),
    left_margin = 10Plots.mm, 
    right_margin = 50Plots.mm, 
    foreground_color_guide = RGB(0.337, 0.631, 0.749),
    ytickfontcolor = RGB(0.337, 0.631, 0.749),
    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.439, 0.368, 0.470),
    linewidth=3, 
    legend = :topright, 
    grid = :off,
    size = (1600, 800),
    left_margin = 10Plots.mm, 
    right_margin = 50Plots.mm, 
    yticks = [280,315,345,380,410],
    foreground_color_guide = RGB(0.439, 0.368, 0.470),
    ytickfontcolor = RGB(0.439, 0.368, 0.470),
    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.352, 0.219),
    linewidth=3, 
    legend = :left, 
    grid = :off,
    size = (1600, 800),
    left_margin = 10Plots.mm, 
    right_margin = 50Plots.mm, 
    foreground_color_guide = RGB(0.949, 0.352, 0.219),
    ytickfontcolor = RGB(0.949, 0.352, 0.219),
    xtickfontsize=a,
    ytickfontsize=a,
    xguidefontsize=a,
    yguidefontsize=a,
    legendfontsize=a)
2 Likes