Announcement

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

  • How to add another variable as a label above stacked bar chart

    Hi,

    First, I want to say that I don't have a good english. So,if something is not understood I can explain it again

    Well, I have some problems with graphs bars in Stata. I want to add another variable as a label above stacked bar chart. I found this link https://www.stata.com/statalist/arch.../msg00911.html but that data base is not acording with mine. "Dpto" is my binary var and "g_L1" my combination of my two categories ("D" and "N"). "Total" is the percentage that I want to show in my stacked bar chart, and I would like to add the var "NV" above stacked bar chart.

    g_L1 Dpto Total NV
    Level1 D 20 500
    Level1 D 20 500
    Level1 D 20 500
    Level1 D 20 500
    Level1 N 33 1000
    Level1 N 33 1000
    Level1 N 33 1000
    Level2 D 45 500
    Level2 D 45 500
    Level2 N 53 1000
    Level2 N 53 1000
    Level2 N 53 1000
    Level2 N 53 1000
    Level3 D 35 500
    Level3 D 35 500
    Level3 N 14 1000
    Level3 N 14 1000
    Level3 N 14 1000

    When I just considered the first three vars (g_L1", "Dpto" and "Total") I run the next sintaxis and it really works, but I want to incorporate the new var "NV" above the chart
    and I don't know how to do it


    splitvallabels g_L1
    graph bar Total, ///
    over(g_L1, label(labsize(small)) relabel(`r(relabel)')) ///
    over(Dpto,label(labsize(small))) ///
    ytitle("Categories", size(small)) ///
    title("Results" ///
    ,span size(medium)) ///
    blabel(bar, pos(center) format(%4.0f)) ///
    intensity(25)///
    asyvars stack


    I hope your help.



    Thanks,
    S.

  • #2
    Hi,
    I'm not sure whether you want to add a label over the graph or over every bar. For the first one, just type in the options of your -graph bar- :
    Code:
    subtitle("this is my label")
    For the second one, you can always add text on the graph itself using this option :
    Code:
    text(y x "this is my label")
    and by replacing x and y by your coordinates on the graph. There is also a plethora of options to this command, don't forget to check the help file.

    Cheers
    LP

    Comment


    • #3
      Originally posted by Leo Picard View Post
      Hi,
      I'm not sure whether you want to add a label over the graph or over every bar. For the first one, just type in the options of your -graph bar- :
      Code:
      subtitle("this is my label")
      For the second one, you can always add text on the graph itself using this option :
      Code:
      text(y x "this is my label")
      and by replacing x and y by your coordinates on the graph. There is also a plethora of options to this command, don't forget to check the help file.

      Cheers
      LP
      Hi! Thanks for your answer


      Yes! I want to add a label, but from other var, which is "NV". I think I should use the command "twoway" because I would use another var.

      Comment

      Working...
      X