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) 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. I arrive with the following code
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.
I have the following questions:
- How can I move the GDP axis to the left side.
- 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?
- How can I change the numbers into a readable format, i.e. 2.0x10^9 to 2 Billion.
Thank you very much in advance =)