Announcement

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

  • incomplete bar legend

    Hey stata experts,

    I am having trouble identifying the problems with my code when doing a bar graph using six legend items. Specifically, I have seven racial groups on x axis and each group is supposed to have six disability types which need to be graphed out. In my codes, I included six bars to represent the six disability types. When I hit do, stata doesn't spit out any errors but the graph's legend looks wrong: three out of six disability types are correctly shown with colors but colors of the rest of the three legend items are missing. I don't know what's wrong with my code. Is this because the graph area is too small to graph all six out? Any suggestions please?

    Below are my codes:

    graph bar SLD SLI AUT, bargap(-30) bar(1, fcolor(dknavy) lcolor(dknavy)) ///
    bar(2, fcolor(dknavy*.7) lcolor(dknavy*.7)) bar(3, fcolor(maroon) lcolor(maroon)) ///
    bar(4, fcolor(maroon*.7) lcolor(maroon*.7)) bar(5,fcolor(dkorange) lcolor(dkorange)) ///
    bar(6, fcolor(dkorange*.7) lcolor(dkorange*.7)) ///
    blabel(bar, position(inside) color(white) format(%10.0f))over(race, ///
    relabel(1 "AsianIndian" 2 "Chinese" 3 "Filipino" 4 "Hmong" 5 "Japanese" 6 "Korean" 7 "OA") ///
    label(labsize(medsmall))) title("Distribution of Disability Types", span)subtitle("by Race", span) ///
    ytitle("Percent", size(medsmall))ylabel(0(20)100, labsize(medsmall) nogrid) ///
    ylabel (0(1.5)8,labsize(medsmall) nogrid) ///
    legend(order(1 "AUT" 2 "SLD" 3 "SLI" 4 "EBD" 5 "MUL" 6 "ID") ring(0) position(11) symxsize(2) symysize(2) rows(2) ///
    size(medsmall) region(lstyle(none) lcolor(none) color(none))) ///
    graphregion(color(white) fcolor(white) lcolor(white))plotregion(color(white) ///
    fcolor(white) lcolor(white) margin(zero))

  • #2
    You only specify 3 variables at the beginning of the graph command (and the order does not match the order in the legend, SLD should be 1, SLI should be 2, AUT should be 3).
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      Carole explained what is wrong with your code. I wanted to add a reproducible example that shows what happens when you only include three variables in a graph but add a legend with six keys.
      Code:
      sysuse auto, clear
      graph bar trunk turn displacement, over(rep78) ///
        legend(order(1 "AUT" 2 "SLD" 3 "SLI" 4 "EBD" 5 "MUL" 6 "ID"))
      On a separate issue, have you considered by() instead of over()?
      Code:
      graph bar trunk turn displacement, by(rep78) ///
        legend(order(1 "AUT" 2 "SLD" 3 "SLI" 4 "EBD" 5 "MUL" 6 "ID"))

      Comment


      • #4
        Thanks guys!

        Comment

        Working...
        X