First time poster here, so please bear with me. I'm using this data:
I'm trying to
using two Y-axes because my three employment variables, emp, total_local_g, and total_emp are of different scales. When I make the graph using the following code:
The graph turns out like this:
It doesn't look bad, but I'd like the axis ticks on the right Y-axis to line up with those on the left Y-axis. I tried to control the number of ticks using the
command but that didn't appear to work. How can I get the axis ticks on both axes to align with the grid?
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long beafips str48 countyname double emp int(year naics) float(total_emp total_local_g) 18043 "Floyd" 851 2001 541 26356 14874.08 18043 "Floyd" 774 2001 332 26356 14874.08 18043 "Floyd" 1632 2001 326 26356 14874.08 18043 "Floyd" 1366 2002 326 26225 15591.977 18043 "Floyd" 745 2002 332 26225 15591.977 18043 "Floyd" 843 2002 541 26225 15591.977 18043 "Floyd" 666 2003 332 27127 16298.873 18043 "Floyd" 936 2003 541 27127 16298.873 18043 "Floyd" 1209 2003 326 27127 16298.873 18043 "Floyd" 1149 2004 326 28075 17058.186 18043 "Floyd" 921 2004 541 28075 17058.186 18043 "Floyd" 635 2004 332 28075 17058.186 18043 "Floyd" 940 2005 541 28699 17209.52 18043 "Floyd" 716 2005 332 28699 17209.52 18043 "Floyd" 1230 2005 326 28699 17209.52 18043 "Floyd" 774 2006 332 29278 17852.584 18043 "Floyd" 941 2006 541 29278 17852.584 18043 "Floyd" 1171 2006 326 29278 17852.584 18043 "Floyd" 1035 2007 326 29153 17654.504 18043 "Floyd" 972 2007 332 29153 17654.504 18043 "Floyd" 1012 2007 541 29153 17654.504 18043 "Floyd" 1018 2008 326 29178 17539.613 18043 "Floyd" 1053 2008 332 29178 17539.613 18043 "Floyd" 1002 2008 541 29178 17539.613 18043 "Floyd" 899 2009 332 27829 18919.979 18043 "Floyd" 958 2009 541 27829 18919.979 18043 "Floyd" 685 2009 326 27829 18919.979 18043 "Floyd" 880 2010 332 28141 18009.676 18043 "Floyd" 971 2010 541 28141 18009.676 18043 "Floyd" 785 2010 326 28141 18009.676 18043 "Floyd" 1025 2011 541 27980 17958.94 18043 "Floyd" 831 2011 326 27980 17958.94 18043 "Floyd" 884 2011 332 27980 17958.94 18043 "Floyd" 1067 2012 541 27801 17802.873 18043 "Floyd" 920 2012 332 27801 17802.873 18043 "Floyd" 928 2012 326 27801 17802.873 18043 "Floyd" 900 2013 332 28357 18206.61 18043 "Floyd" 1068 2013 541 28357 18206.61 18043 "Floyd" 1103 2013 326 28357 18206.61 18043 "Floyd" 1062 2014 541 28121 17828.709 18043 "Floyd" 1200 2014 326 28121 17828.709 18043 "Floyd" 946 2014 332 28121 17828.709 18043 "Floyd" 1274 2015 326 28939 18186.248 18043 "Floyd" 1098 2015 541 28939 18186.248 18043 "Floyd" 948 2015 332 28939 18186.248 18043 "Floyd" 1150 2016 326 29406 18759.494 18043 "Floyd" 1146 2016 541 29406 18759.494 18043 "Floyd" 912 2016 332 29406 18759.494 end format %ty year
Code:
graph tw line
Code:
graph tw /// (line emp year if beafips == 18043 & naics == 326, yaxis(1) ylabel(#3, axis(1))) /// (line emp year if beafips == 18043 & naics == 541, yaxis(1) ylabel(#3, axis(1))) /// (line emp year if beafips == 18043 & naics == 332, yaxis(1) ylabel(#3, axis(1))) /// (line total_local_g year if beafips == 18043, yaxis(2) ylabel(#3, axis(2))) /// (line total_emp year if beafips == 18043, yaxis(2) ylabel(#3, axis(2))), /// legend(label(1 "naics 326") label(2 "naics 541") label(3 "naics 332"))
It doesn't look bad, but I'd like the axis ticks on the right Y-axis to line up with those on the left Y-axis. I tried to control the number of ticks using the
Code:
ylabel(#3)
Comment