Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Eliminate gaps and sort categorical variable in horizontal range plot (rbar)

    Hello,
    I'm trying to create a rather complicated graph and I am stuck on three last issues (code and resulting graph below and attached):
    1. I would like to eliminate the blank space on the y axis for the missing values of the categorical variable I do not want to display
    2. I would like to sort the order of the y-axis variables either manually or by the value of a variable in descending order (hnar_median)
    3. I would like to include a legend and make the size of the symbol corresponding to the second rbar smaller (where I've made the bar width on the graph scaled to .1)
    I can't even figure out how to do the first two things on the list in the graph editor, so I'm hoping someone can help with the code.

    Thanks so much,
    Kate

    Code:
        tw rbar HNAR_p25 HNAR_p75 nutr_no if data_round==1 ///
                & inlist(nutr_no,3,4,5,6,8,9,13,14,15,16,22) & scenario==1, horizontal barwidth(.80) ///
                color(emidblue) fcolor(emidblue) || ///
            rbar HNAR_p25 HNAR_p75 nutr_no if data_round==1 ///
                & inlist(nutr_no,3,4,5,6,8,9,13,14,15,16,22) & scenario==2, horizontal barwidth(.1) ///
                lcolor(green) fcolor(green) ///
            xline(1, lcolor(black)) ytitle("Nutrient", size(small) margin(1 3 0 0)) ///
            xtitle("Percent of Nutrient Need Met in Household Diet", size(small) margin(1 1 1 1)) ///
            xlabel(0 "0" .5 "50%" 1 "100%" 1.5 "150%" 2 "200%") yscale(range(15 6 16 14 5 9 13 22 4 3)) ///
            ylabel(, val angle(horizontal) labsize(vsmall) nogrid) ///
            graphregion(color(gs15)) xtitle("2010", size(small) margin(1 1 1 1)) || ///
            scatter nutr_no HNAR_p50 if data_round==1 & inlist(nutr_no,3,4,5,6,8,9,13,14,15,16,22) & scenario==1, ///
                 mcolor(navy) msymbol(smcircle) msize(*1) ylabel(3 4 5 6 8 9 13 14 15 16 22, val angle(horizontal) labsize(vsmall) nogrid) || ///
            scatter nutr_no HNAR_p50 if data_round==1 & inlist(nutr_no,3,4,5,6,8,9,13,14,15,16,22) & scenario==2, ///
                 mcolor(dkgreen) msymbol(smcircle) msize(*1) ylabel(3 4 5 6 8 9 13 14 15 16 22, val angle(horizontal) labsize(vsmall) nogrid) || ///
            scatter nutr_no HNAR_mean if data_round==1 & inlist(nutr_no,3,4,5,6,8,9,13,14,15,16,22) & scenario==1, ///
                 mcolor(navy)  msymbol(pipe) msize(*2) ylabel(3 4 5 6 8 9 13 14 15 16 22, val angle(horizontal) labsize(vsmall) nogrid) || ///
            scatter nutr_no HNAR_mean if data_round==1 & inlist(nutr_no,3,4,5,6,8,9,13,14,15,16,22) & scenario==2, ///
                 mcolor(dkgreen) msymbol(pipe) msize(*2) legend(off)
    Here is a link to the image.

    Thanks so much!!!

  • #2
    Solution: create a new variable of the nutrient that only contains the values I want to visualize and gives them numeric value in the order to appear on the graph. Still haven't solved the legend problem but at least that can likely be fixed in the graph editor.

    Hope this might help someone else in the future who also needs to sleep on it to figure out a workaround!

    Comment

    Working...
    X