Announcement

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

  • Box and whispers label on y axis

    Hi all,

    I would like to create a graph that has box and whisker plots for 5 questions like this one:

    Attempt at box whiskers.png

    However, I would like the labels in the legend to be on the y axis corresponding to each question. I think one way would just be to reshape the data, make one variable with all 5 of these responses, and then just do hbar newvar, over(components). This would correspond to an example in the box help file. I wonder if there is a way to do this without the reshape? I tried playing around with the position of the legend but it gave me funky graphs.

    Thanks for your help.

    Best,
    Patryk

  • #2
    Hello Patryk

    Unfortunately, you didn't provide the command, as recommended in the FAQ. That said, I gather you used the option "asyvars".

    Being this so, you can exclude this option, making sure you created the labels for the variable.

    Please see the toy example below:

    Code:
    . sysuse auto
    (1978 Automobile Data)
    
    . label define mylabel 1 "small" 2 "medium" 3 "big" 4 "extra " 5 "you name it"
    
    . label values rep78 mylabel
    
    . graph hbox mpg, over(rep78)
    Click image for larger version

Name:	Graph_bar_h.png
Views:	1
Size:	13.1 KB
ID:	1375372



    Hopefully that helps.
    Best regards,

    Marcos

    Comment


    • #3
      Marcos is bang on in underlining that there is no code in #1 to discuss (or a data example!). He is guessing that you have one variable, but my guess is that you have 5 variables here, one for each question.

      Watch out also: for graph bar, graph dot, graph box and their horizontal siblings, the y axis is always the quantitative axis (which in these examples happens to be horizontal).

      You can get horizontal box plots without reshape by using stripplot (SSC). Here is a dopey example:

      Code:
      sysuse auto, clear
      stripplot turn trunk mpg, box(barw(0.1))  boffset(-0.15) iqr(1.5) variablelabels yla(, noticks) stack height(0.7) xtitle("")
      Click image for larger version

Name:	yaboxplot.png
Views:	1
Size:	19.7 KB
ID:	1375381


      EDIT: Showing the original data, perhaps as a tabulation, might elicit other suggestions of how to plot them.
      Last edited by Nick Cox; 22 Feb 2017, 08:16.

      Comment


      • #4
        Thanks, Nick-- that's exactly what I was looking for. Sorry for not including my earlier code.

        Comment


        • #5
          To better prepare for future posts to Statalist, please review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question. The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

          Comment

          Working...
          X