Announcement

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

  • Changing the order of bars in a box plot

    Hi!

    I want to make a box plot of distribution of 6 different scores (score 1-6) by a grouping variable (group, values 0 and 1). Using the following syntax, I get the shown box plot in Stata.

    graph box Score1 Score2 Score3 Score4 Score5 Score 6, over(group)



    However, I want my box plot to compare score 1 between groups 0 and 1, then score 2 between groups 0 and 1, etc, and not first all scores for group 0 and then for group 1. So the box plot should look something like this:




    I can not figure out how to manage this in Stata. Can anybody help me?

  • #2
    Your graphs are not visible. Always upload in .png format as advised in the FAQs. Here is a reproducible example that may help.

    Code:
    sysuse auto, clear
    *REPLICATE GRAPH
    replace disp = disp*20
    rename (price disp weight) (Score#), addnumber(1)
    set scheme s1color
    graph box Score?, over(foreign) leg(row(3)) saving(gr1, replace)
    
    *SOME TECHNIQUE 
    reshape long Score, i(make) j(which)
    lab def which 1 "Price" 2 "Displacement" 3 "Weight"
    lab values which which
    separate Score, by(foreign) 
    graph box Score?, over(which) leg(order(1 "Domestic" 2 "Foreign")) saving(gr2, replace)
    gr combine gr1.gph gr2.gph
    Res.:

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	20.4 KB
ID:	1588970

    Comment


    • #3
      Thank you, here are the attached figures. The sketch-version is the result I am hoping for.
      Attached Files

      Comment


      • #4
        See also https://www.stata-journal.com/articl...article=gr0062

        Comment

        Working...
        X