Announcement

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

  • Multiple box plots on one graph by another variable, sequentially

    Hi all,

    I am trying to create a figure for box plots that includes multiple variables - but I want to stratify by another variable (whether the response is from a nurse or a doctor).
    What I have is this code:
    graph hbox Q1_1 Q1_6 Q1_7 Q1_9 Q1_12 Q1_3 Q1_16 Q1_18 Q1_17 Q1_19 Q1_15, by(Doc_nurse) asy noout legend(col(1) ring(0) position(1))

    but I don't want a legend for each question, I want these listed on the right by their box plot and a legend for the stratified variable (nurse vs doctor). The resulting graph is shown at the end.

    What I want is to have one graph like so

    Q1_1 -> nurse response
    Q1_1 -> doctor repsonse
    Q1_3 -> nurse
    Q1_3 -> doc
    etc. for the remaining variables

    with a legend for just either nurse or doctor response, with the variable name for each on the right hand side.

    Is this possible? I have tried using the -combine- command but this has limited options for axis, and basically leads to the same issue.

    any help would be appreciated, thank you in advance!
    N





  • #2
    Sorry, I can't read your image. What we recommend here for images is .png. See FAQ Advice #12.

    A sample dataset, real or realistic, would help greatly. By the sound of it, four variables would be enough to show the principle. See again FAQ Advice #12.

    Did you check out this Tip?

    SJ-14-4 gr0062 . . . . . . . . . . . . Stata tip 121: Box plots side by side
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
    Q4/14 SJ 14(4):991--996 (no commands)
    tip on how to and which data should be plotted side by
    side with box plots



    Comment


    • #3
      I don't know why the image didn't show up, I uploaded through statalist and it shows up on mine in the post (and it was a .png). I also can't access that paper its behind a paywall - even through institutional libraries.


      example data (Q1_1 etc. are likert scale survey data):
      Study Q1_1 Q1_3 Q1_6 Doc_nurse
      1 2 4 7 doctor
      2 1 3 10 nurse
      3 3 4 2 doctor
      4 5 9 3 nurse
      5 4 10 4 nurse
      6 10 1 5 nurse
      7 9 2 10 doctor
      8 7 1 3 nurse

      Comment


      • #4
        It's worth paying for, naturally. The main idea is that you may need a reshape to make progress.

        Your data example is helpful. Using dataex (SSC) would have been even more helpful: again please see Advice #12.

        Here is a token example.

        Code:
        clear
        input Study    Q1_1    Q1_3    Q1_6 str6 Doc_nurse
        1    2    4    7    doctor
        2    1    3    10    nurse
        3    3    4    2    doctor
        4    5    9    3    nurse
        5    4    10    4    nurse
        6    10    1    5    nurse
        7    9    2    10    doctor
        8    7    1    3    nurse
        end
        
        reshape long Q1_ , i(Study) j(Question)
        rename Q1_ Answer
        graph hbox Answer, over(Doc_nurse) over(Question)

        Comment

        Working...
        X