# Quelle (2021 vorläufig):
# Treibhausgas-Emissionen in Deutschland, 15.03.2022, Daten: Tabelle 1, https://www.umweltbundesamt.de/sites/default/files/medien/384/bilder/3_tab_emi-direkt-indirekt-thg_2022.png, abgerufen am 01. Januar 2023
1990,1052,190,1,1,1242
…,0,0,1,1,0
1995,939,177,1,1,1116
…,0,0,1,1,0
2000,899,138,1,1,1037
…,0,0,1,1,0
2005,866,127,1,1,993
…,0,0,1,1,0
2010,833,103,0.21,0.21,936
2011,809,102,0.21,0.21,911
2012,814,103,0.21,0.21,917
2013,831,103,1,1,934
2014,792,102,1,1,894
2015,796,102,1,1,898
2016,800,101,1,1,901
2017,786,100,1,1,886
2018,754,97,1,1,851
2019,707,93,1,1,800
2020,639,90,0.4,0.4,729
2021,675,87,1,1,762
…,0,0,1,1,0
2030,0,0,0.65,0.65,0
…,0,0,1,1,0
2040,0,0,0.88,0.88,0
…,0,0,1,1,0
2045,0,0,1,0.99,0
set terminal svg size 840 500 enhanced fname "Liberation Sans" # fsize 10
set output "THG_Emissionen_DE_UBA-de.svg"
set title "Treibhausgasemissionen in Deutschland 1990–2021" font "Liberation Sans, 25"
set datafile missing '"#N/A"'
set datafile separator ","
set key invert
set label 'Daten: Treibhausgas-Emissionen in Deutschland 2020' font ',8' at screen 0.995,0.045 right
set label '(ohne Landnutzungsänderungen, 2021: vorläufig)' font ',8' at screen 0.995,0.02 right
# white background
set obj 1 rectangle behind from screen 0,0 to screen 1,1
set obj 1 fillstyle solid 1.0 fillcolor rgbcolor "white"
set obj 2 rectangle behind from graph 0,0 to graph 1,1
set obj 2 fillstyle solid 1.0 fillcolor rgbcolor "#F2FFFF"
set grid noxtics ytics lt 0 lw 1 lc rgb "grey95"
set yrange [0:1350]
set xtics out nomirror scale 0 offset -1,0 rotate by -60
set ytics out mirror 0,100,1300
set mytics 2
set ylabel 'Emissionen in Mio. t CO_{2}eq' font ',16'
set xlabel 'Jahr' font ',16'
set boxwidth 1 relative
set style data histograms
set style histogram rowstacked
set style fill solid 1.0 border -1
set label "1. Kyoto-\nVerpflichtungsperiode:\n–21%" at 9,1150 center font "bold,10"
set label "2020:\n–40%" at 18,900 center font ",10"
set label "2045:\n–100%" at 25,100 center font ",10"
# the following plots are done:
# 1: light grey boxes of width one for targets if there is a target range, depicts upper limit
# 2: grey boxes of width one for target
# 3: stacked bar: emissions of other greenhouse gases
# 4: stacked bar: CO2 emissions
# 5: labels (absolute values) of other greenhouse gas emissions
# 6: labels (absolute values) of CO2 emissions
# 7: labels (absolute values) sum of emissions
# 8: labels (absolute values) of upper limit of target-range, only if there is one and there are no emissions for that year yet
# 9: labels (absolute values) of target-range, only if there are no emissions for that year yet
#10: labels (percentage) of total greenhouse gas emission reductions
#11: labels (percentage) of target reduction
#12: labels (percentage) of target reduction range
plot '20230101_THG_Emissionen_D.csv' using 0:(1251*(1-$4)):(1) title "" with boxes fs solid 1.0 noborder linecolor rgb "#F5F5F5", \
'' using 0:(1251*(1-$5)):(1) title "Minderungsziele" with boxes fs solid 1.0 noborder linecolor rgb "grey95", \
'' using 2 title "CO_2" linecolor rgb "#FFD700", \
'' using 3:xtic(1) title "CH_4,NO_2,F-Gase" linecolor rgb "#FF8C00", \
'' using 0:2:($3>0?$3:"") with labels font ",10" offset 0,1 notitle, \
'' using 0:(40):($2>0?$2:"") with labels font ",10" notitle, \
'' using 0:($2+$3):($2+$3>0?sprintf("%d",($2+$3)):"") with labels offset 0,0.5 font ",10" notitle, \
'' using 0:(40):($2==0 && $4>=0.3 && $4<1 && $4!=$5 ? sprintf("%d",(1251*(1-$5))) : "") with labels font ",10" notitle, \
'' using 0:(1251*(1-$4)):($2==0 && $4>=0.3 && $4<1 ? sprintf("%d",(1251*(1-$4))) : "") with labels offset 0,0.5 font ",10" notitle, \
'' using 0:(($2+$3)/2):($2>0 ? sprintf("–%d%",(100*(1251-$2-$3)/1251)):"") with labels font ",8" notitle, \
'' using 0:(1251*(1-$4)/2):($4>=0.3 && $4<1 && $4==$5 ? sprintf("–%d%",($4*100)):"") with labels font ",8" notitle, \
'' using 0:(1251*(1-$4)/2):($4>=0.3 && $4<1 && $4!=$5 ? sprintf("–%d%%\n–\n–%d%",($4*100),($5*100)):"") with labels offset 0,1.4 font ",8" notitle