Dear All,
I am trying to create a bar chart (see attached), but am having difficulty adding a little gap between the bars for each year. I.e., I want a little space added between the bar for Whites in a given year and the bar for All of the subsequent year.
Below are the dataex and code that created the attached graph.
Would be grateful for any help you may be able to offer.
Sumedha
I am trying to create a bar chart (see attached), but am having difficulty adding a little gap between the bars for each year. I.e., I want a little space added between the bar for Whites in a given year and the bar for All of the subsequent year.
Below are the dataex and code that created the attached graph.
Would be grateful for any help you may be able to offer.
Sumedha
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int year double(pctMOUDcondOUDA pctMOUDcondOUDB pctMOUDcondOUDH pctMOUDcondOUDW) float pctMOUDcondOUDwoU str3 payer float(type1 type2 type3 type4 type0 type5 type6 type7 type8 type9) 2016 3.39 4.62 2.61 4.33 4.1372952 "MCR" 2015.6 2015.8 2016.2 2016.4 2016.6 2015.47 2015.68 2015.88 2016.08 2016.28 2017 2.89 4.09 2.64 4.5 4.1770897 "MCR" 2016.6 2016.8 2017.2 2017.4 2017.6 2016.47 2016.68 2016.88 2017.08 2017.28 2018 2.75 4.49 2.57 4.82 4.4405007 "MCR" 2017.6 2017.8 2018.2 2018.4 2018.6 2017.47 2017.68 2017.88 2018.08 2018.28 2019 2.9 5.2 2.88 5.57 5.120433 "MCR" 2018.6 2018.8 2019.2 2019.4 2019.6 2018.47 2018.68 2018.88 2019.08 2019.28 2020 3.86 6.92 3.2 6.64 6.177121 "MCR" 2019.6 2019.8 2020.2 2020.4 2020.6 2019.47 2019.68 2019.88 2020.08 2020.28 2021 4.95 7.55 3.85 7.32 6.910174 "MCR" 2020.6 2020.8 2021.2 2021.4 2021.6 2020.47 2020.68 2020.88 2021.08 2021.28 end
Code:
twoway (bar pctMOUDcondOUDwoU type1 if payer=="MCR", barwidth(.2) bcol(black)) || /// (bar pctMOUDcondOUDA type2 if payer=="MCR", barwidth(.2) bcol(khaki)) || /// (bar pctMOUDcondOUDB type if payer=="MCR", barwidth(.2) bcol(gs7*.35)) || /// (bar pctMOUDcondOUDH type3 if payer=="MCR", barwidth(.2) bcol(cranberry*.55)) /*||*/ /// (bar pctMOUDcondOUDW type4 if payer=="MCR", barwidth(.2) bcol(navy)) || /// (scatter pctMOUDcondOUDwoU type5 if payer=="MCR", mlabp(1) msymbol(none) mlabel(pctMOUDcondOUDwoU) mcol(black) mlabsize(2)) || /// (scatter pctMOUDcondOUDA type6 if payer=="MCR", mlabp(1) msymbol(none) mlabel(pctMOUDcondOUDA) mcol(black) mlabsize(2)) || /// (scatter pctMOUDcondOUDB type7 if payer=="MCR", mlabp(1) msymbol(none) mlabel(pctMOUDcondOUDB) mcol(black) mlabsize(2)) || /// (scatter pctMOUDcondOUDH type8 if payer=="MCR", mlabp(1) msymbol(none) mlabel(pctMOUDcondOUDH) mcol(black) mlabsize(2)) || /// (scatter pctMOUDcondOUDW type9 if payer=="MCR", mlabp(1) msymbol(none) mlabel(pctMOUDcondOUDW) mcol(black) mlabsize(2)), /// title("(b) Medicare Advantage", pos(11)) /// legend(order(1 " All" 2 "Asian" 3 "Black" 4 "Hispanic" 5 "White") pos(6) cols(5)) /// xlabel( 2016 "2016" 2017 "2017" 2018 "2018" 2019 "2019" 2020 "2020" 2021 "2021") /// ytitle("% with OUD Dx receiving MOUD", size(2.5)) xtitle("") name(b, replace)
Comment