Announcement

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

  • customizing legend text for stacked bar graphs

    dear all,

    I am graphing stacked bars by a category and somehow cannot find a way to customize the text of the legend. say the dataset looks something like this

    country thing1 thing2
    A .5 .5
    B .3 .7

    graph thing1 thing2, stack over(country)

    it will then say "mean of thing1" and "mean of thing2" in the legend. I know how to turn the legend off completely. However, I'd rather like to either use the varnames directly (without "mean of"), labels, or a custom text.

    I know this is probably very easy to solve but I couldn't find a solution despite looking for a long time now..
    Best,
    Swati

  • #2
    That code is illegal, but assuming that you meant some command starting graph bar or graph hbar then reading

    Code:
    help graph bar 
    will tell you the answer. graph bar calculates bars for means unless you tell it otherwise. In this case, I guess that you need a command starting

    Code:
    graph bar (asis)
    Your reading order should always start with

    1. the help
    2. the manual entry
    3. StataCorp FAQs
    4. high quality texts or expository papers
    5. Statalist

    so I wonder what reading order you followed instead.

    Comment


    • #3
      Nick, the help did not give me the answer this is why I posted here. I read through most of the help, especially legend(ing options), the manual, both printed as well as the "current" (i.e. for stata14 that I'm using) pdf many old statalist emails.

      I have no problem with graph bar calculating means, the number itself is correct, it's just about the legend.
      Can't you just tell me the answer instead of all this?

      Comment


      • #4
        I've told you the answer. My suggestion -- which has to be a guess because your code is illegal and could not possibly run -- is to start your code with


        Code:
        graph bar (asis)
        I've also given you advice about how to find out for yourself. That's two for one, not zero as you imply.

        Did you even try implementing my answer?

        P.S. I also checked the help. The help prominently shows (asis) as a possible syntax element and gives examples using it.

        Comment


        • #5
          Hello Swati,

          In the legend options for graph bar, you will see a suboption called label(). I believe that is what you are looking for.

          Edit: After rereading your post, I believe Nick's solution is more verbatim what you want. The solution I proposed requires you to put in "custom text."
          Last edited by Roger Chu; 12 Dec 2016, 12:30.

          Comment

          Working...
          X