Hi,
There are a couple of issues (there may be more) with the below stacked area graph based on the -dataex- example data.
1. The red reference line is in the background
2. There is some whitepace between the axis lines and the stacked area region along both x and y axis
I am using nicelabels and mylabels from Nick Cox, which can be installed from here:

I would like to bring the red reference line to the front and remove the whitespace along the x and y axis. This graph is created in Stata 17.0. Any suggestions are appreciated.
Edit: Added the tsset command before twoway graph
There are a couple of issues (there may be more) with the below stacked area graph based on the -dataex- example data.
1. The red reference line is in the background
2. There is some whitepace between the axis lines and the stacked area region along both x and y axis
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(year v1 v2 v3 v4 v5 v6 v7 v8 v9 v10) 1995 11495.99 296097.3 224771.3 2304.07 102958.4 47893.72 3268.61 492.7 99000.56 1911.79 1996 11863.57 297131.3 229418.55 2336.07 104126.4 48069.42 3394.51 492.7 99054.65 1940.09 1997 11980.65 297267.22 233146.3 2336.07 102531.1 48490.07 3584.11 494.01 99121.72 1957.2 1998 12164.21 297249.22 234513.2 2336.07 100335.1 48423.41 3705.23 494.11 99120.95 2113.44 1999 12373.01 296967.34 243749.94 2336.07 100335.1 48289.92 3982.21 495.03 99304.5 2881.54 2000 12208.17 297182.22 272310.47 2396.07 100335.1 48713.98 3979.43 495.66 99306.78 2939.36 2001 12366.61 297144.9 313784.5 2396.07 100335.1 48857.57 3870.73 501.24 99386.82 4432.35 2002 12423.38 297498.94 375165 2477.68 100662.7 48022.85 3958.49 507.65 100343.6 5044.74 2003 12692.96 295831.47 422873.3 2510.08 101048.33 47428.45 3997.4 511.67 100335.38 6695.51 2004 12671.68 295531.94 439250.6 2487.11 101397.98 47034.5 4021.02 511.78 100504.31 7107.42 2005 12678.71 295671.78 450432.9 2521.61 101533.82 46623.03 3961.44 528.57 100461.35 9134.03 2006 12751.96 295621.6 458442.9 2546.82 101778.18 45917.04 3963.18 536.51 100822.63 11871.35 2007 13010.17 295659.4 461522.8 2528.9 101891.3 45615.84 3941.68 652.59 100416.9 17162.87 2008 13134.28 295754.13 466711.4 2580.15 102482.7 45282.45 3997.28 735.47 100621.84 25609.51 2009 13481 296249.13 472368.7 2774.55 102637.7 44879.04 3993.08 892.56 101114.06 35608.12 2010 13728.07 301267.22 477145.4 2793.55 102756.5 43370.36 4029.78 1168.45 101565.27 40616.26 2011 13973.87 300587.94 482640.6 2763.85 103593.1 42397.86 4026.98 2074.28 102206.25 46556.45 2012 14283.29 293931.28 486262.9 2927.15 104531.9 40355.22 3909.98 3696.58 102448.92 60079.96 2013 14839.9 288572.84 489235.25 2975.15 101006.55 38394.84 3979.68 7378.68 102662.5 61023.25 2014 14827.82 284264.94 496246.1 2900.95 101471.9 37244.84 3970.78 11259.01 103214.72 66133.78 2015 14861.56 270393.75 495808.9 2945.25 100899.7 35349.73 4145.68 14857.06 103237.28 73825.73 2016 14735.16 260574.5 501143.8 2945.75 101958.4 34953.23 4111.38 22988.71 103497.8 82324.68 2017 14675.82 255152.7 506253.2 2888.46 101911.3 33638.73 4215.18 28676.2 103701.1 89540.99 2018 14304.72 242636.66 521550.8 2925.85 101500.4 33160 4369.18 33523.65 103819.8 96467.86 2019 13907.92 227119.16 525830.25 3070.15 100145.3 31113.35 4515.78 39071.95 103600.22 105601.47 2020 13652.32 218367.84 528469.94 3094.95 98680.5 30566.25 5222.73 49470.12 104115.82 121429.81 2021 13436.6 212191.55 534143.9 3119.75 97641.7 29040.05 6746.96 62937.29 104224.56 135373.16 2022 13374.9 201164.55 544985.5 3204.15 96826.1 28580.95 11223.94 92660.33 104096.66 152626.84 2023 13414.7 196331.34 552029.7 3310.25 99054.1 28567.95 20221.68 162682.73 105000.69 168034.67 2024 13443.9 194787.34 555304 3529.15 97932.1 28535.55 26272.07 210914.5 105065.54 184544.83 2025 13521.9 188653.25 565561.6 3529.15 96814.1 28535.55 28116.17 233478.83 105226.54 196616.73 end
Code:
// Generating additive values for stacked area graph gen v11 = v1 + v4 + v6 + v7 gen v2_add = v3 + v2 gen v11_add = v2_add + v11 gen v5_add = v11_add + v5 gen v9_add = v5_add + v9 gen v10_add = v9_add + v10 gen v8_add = v10_add + v8 // Finding the max value for labeling su v8_add local ymax = r(max) / 1000 // Dividing by 1000 because the display labels are in GW while the actual data is in MW nicelabels 0 `ymax', local(mylbl) nvals(10) tight mylabels `mylbl', myscale(@ * 1000) format(%5.0fc) local(mylbl) // Finding the year range for labeling su year local tmin = r(min) local tmax = r(max) mylabels `tmin'(5)`tmax', local(mytlbl) tsset year twoway /// (area v8_add year) /// (area v10_add year) /// (area v9_add year) /// (area v5_add year) /// (area v11_add year) /// (area v2_add year) /// (area v3 year), /// tlabel(`mytlbl') /// tline(2023) /// legend(row(2)) /// xtitle("") /// ylabel(`mylbl', angle(0)) /// ytitle("Capacity (GW)") /// title(Capacity)
I am using nicelabels and mylabels from Nick Cox, which can be installed from here:
Code:
net install gr0092.pkg
I would like to bring the red reference line to the front and remove the whitespace along the x and y axis. This graph is created in Stata 17.0. Any suggestions are appreciated.
Edit: Added the tsset command before twoway graph
Comment