Announcement

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

  • Adding an extra bar to an hbar graph

    Dear all,

    I am using stata 17 and have produced an hbar graph with the following code:

    graph hbar, over(nonwhite) over(season, relabel(1 "Season 16/17" 2 "Season 17/18" 3 "Season 18/19" 4 "Season 19/20" 5 "Season 20/21")) blabel(bar, format(%2.1f) size(vsmall)) asyvars bargap(10) graphregion(color(white)) percentages bar(1, col(navy%40)) bar(2, col(navy%80)) name(nonwhite_S, replace) title("Skin color shares over seasons", position(12) span ring(7) size(small)) ylabel(20 40 60 80) ytitle("percent") graphregion(color(white)) legend(col(2) label(1 "White players") label(2 "Nonwhite players") symxsize(3))

    I would like to add additional bars (for the nonwhite dummy) over all five seasons to the graph. Is this possible?

    I would appreciate any help!

    Kind regards,

    Eric

  • #2
    Code:
    sysuse auto, clear
    set scheme s1mono
    gr hbar (sum) price, over(rep78) ytitle("USD") saving(gr1, replace)
    expand 2, g(new)
    replace rep78=99 if new
    gr hbar (sum) price, over(rep78, relabel(6 "Total")) ytitle("USD") saving(gr2, replace)
    gr combine gr1.gph gr2.gph, col(1) xcommon
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	16.2 KB
ID:	1704784

    Comment


    • #3
      Thank you, Andrew! I was not familiar with the expand command. This made it rather simple.

      Comment


      • #4
        For more on Andrew Musau's method, see https://www.stata-journal.com/articl...article=gr0058

        Comment


        • #5
          This looks also interesting, Nick. Thanks!

          Comment

          Working...
          X