Announcement

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

  • Labelling Y-axis with graph hbox

    Hi All,


    I have the following dataset:


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(x1 x2)
     5  3
     4 21
     1  3
     4 21
    41  3
     5  1
     2  2
     4  4
    32 32
    31 32
    end

    The box-whiskers plot is a very nice way of graphing a distribution of multiple variables/groups in one group. To that end, I use the commadn:

    Code:
    graph hbox x1 x2.
    Generally, speaking, the syntax for the hbox is something along the lines of:
    Code:
    graph hbox y1 y2, over(x)

    wherein y1 and y2 represent different groups with the same underlying variable x. Put differently, y1 and y2 are conditional distributions of x for the two distinct groups. In my code, however, I have two distinct variables x1 and x2, which I am able to graph together because their scales are similar. Although I obtain the graphs, I get a legend for each of the different variables (x1 and x2), and no label on the y axis. What I would like instead is to have a label on the y-axis itself, correspond to x1 and x2. Is this possible?


    Thanks!




  • #2
    Is this what you wish?

    Code:
    graph hbox x1 x2,  showyvars legend(off)
    Best regards,

    Marcos

    Comment


    • #3
      With data like these you have plenty of space to show -- and then to think about -- the detail in the distribution. To an experienced eye the closeness of median and lower quartile in each box hints at bunching. A quantile-box plot (stripplot, SSC) gives the full story, which a visual scan of the listing supports. I'd call these data bimodal and suggest that the box plot doesn't do a good job at showing that.

      Code:
      stripplot x1 x2, box cumul centre vertical height(0.4) xla(, noticks)
      Click image for larger version

Name:	box_or_qbox.png
Views:	1
Size:	23.4 KB
ID:	1469575

      Click image for larger version

Name:	box_or_qbox2.png
Views:	1
Size:	25.8 KB
ID:	1469576

      Comment


      • #4
        Wow, many thanks Nick Cox Marcos Almeida . I will definitely be thanking statalist in my PhD chapters...

        Comment


        • #5
          Nick Cox Marcos Almeida , on a separate note ( I am not sure if this follow up merits a separate thread), but I am unable to edit the variable names itself on the graph. The variable x1 is uninformative and not self contained. More precisely, I want it to be titled say Var(x1)/Var(x2). This is an illegal stata variable name, so I am unable to change the underlying variable name using the rename command. I have generally been able to modify the names to include otherwise illegal characters on the graph editor itself, but to no avail in this case. Do you have any suggestions?

          Comment


          • #6
            "the graph": which one do you mean? Why is Var(x1)/Var(x2) more informative any way?

            Comment


            • #7
              I was referring to the hbox type box and whiskers plot. I just wanted to describe the variable names beyond x1 and x2, which are not informative by themselves. However, this description would ideally contain parantheses and/or obliques. For instance, I would just want to re-label them (so x1 could be GDP growth) , or "GDP Growth/ World Average"

              Code:
               
               graph hbox x1 x2,  showyvars legend(off)
              does not allow modifying the variable names beyond that which they are called.

              Comment


              • #8
                OK: but always, always give pertinent code if you have it.

                Otherwise -- apart from the guesswork -- if you're expecting people to re-read threads and cobble together data and code from previous answers that's unfair. Make it easy for us to help you.

                That said, this may help:


                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input float(x1 x2)
                 5  3
                 4 21
                 1  3
                 4 21
                41  3
                 5  1
                 2  2
                 4  4
                32 32
                31 32
                end
                label var x1 "whatever" 
                label var x2 "something else" 
                graph hbox x1 x2 , showyvars legend(off) l1title(extra stuff here) 
                graph hbox x1 x2 , legend(off) l1title(extra stuff here)

                Comment


                • #9
                  Thank you, Nick Cox . I'll keep your advice in mind for future questions.

                  Comment


                  • #10
                    For instance, I would just want to re-label them (so x1 could be GDP growth) , or "GDP Growth/ World Average"
                    No problem. I don't know why it didn't work for you, but you just need to type this:
                    Code:
                    label variable x1 "GPF Growth/World average"
                    label variable x2 "My variable is cute"
                    graph hbox x1 x2,  showyvars legend(off)
                    Click image for larger version

Name:	Graph222.png
Views:	1
Size:	31.7 KB
ID:	1469683



                    Hopefully that helps.
                    Best regards,

                    Marcos

                    Comment

                    Working...
                    X