Announcement

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

  • Using variable names and not variable descriptions for box plots

    Hi,

    I have data such as:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(Y1skills_academicstudies Y1skills_doctor Y1feedback_helpful Y1skills_overall treatment)
    2 1 2  4 0
    1 1 1  1 0
    1 1 1  1 0
    3 3 1  4 0
    3 2 1  4 0
    5 5 4  7 0
    2 1 1  3 0
    2 2 1  3 0
    2 2 2  5 0
    1 1 1  1 0
    1 1 3  3 0
    1 2 1  3 0
    1 1 1  1 0
    4 3 2  6 0
    6 6 6  8 0
    3 2 1  3 0
    3 3 1  2 0
    2 1 1  2 0
    2 1 3  3 0
    5 5 6  7 0
    5 5 2  6 0
    4 6 6  4 0
    1 1 2  2 0
    1 1 1  2 0
    6 6 5  7 0
    2 2 6  2 0
    6 5 6  6 0
    2 2 3  3 0
    1 2 1  4 0
    6 3 5  7 0
    6 5 1  6 0
    1 3 1  3 0
    6 5 5  7 0
    3 2 4  5 0
    5 4 5  5 0
    4 1 2  6 0
    2 1 2  2 0
    1 1 2  1 0
    3 3 1  . 0
    7 5 6  8 0
    3 3 2  2 0
    5 5 6  6 0
    5 5 5  6 0
    4 4 5  4 0
    5 3 1  6 0
    2 2 2  1 0
    3 3 5  2 0
    3 3 5  3 0
    5 3 3  4 0
    4 6 3  6 0
    2 2 2  3 0
    1 1 4  1 0
    2 2 1  3 0
    2 2 4  2 0
    1 1 1  2 0
    6 6 6  9 0
    2 2 7  4 0
    6 3 2  8 0
    1 1 1  1 0
    5 2 2  6 0
    2 1 2  3 0
    6 6 6  8 0
    5 5 3  5 0
    5 5 6  6 0
    1 1 1  3 0
    7 5 6  7 0
    2 4 2  3 0
    7 7 6  9 1
    7 7 7  9 1
    5 5 5  6 1
    5 4 3  5 1
    3 3 3  4 1
    3 3 4  7 1
    6 5 7  8 1
    7 6 6  7 1
    5 5 6  7 1
    5 5 5  6 1
    6 6 6  7 1
    6 5 4  7 1
    6 6 3  7 1
    6 5 5  8 1
    6 6 5  7 1
    5 2 7  7 1
    6 6 4  7 1
    6 6 6  7 1
    5 6 3  7 1
    2 2 6  4 1
    7 7 7  9 1
    6 6 7  7 1
    6 6 5  7 1
    6 7 5 10 1
    7 7 7  8 1
    5 4 5  7 1
    7 6 7  8 1
    7 6 6  8 1
    6 5 6  8 1
    5 5 2  5 1
    6 5 6  7 1
    5 5 3  8 1
    6 3 6  8 1
    end
    I want to create a box plot of the first four variables over treatment. The problem I am having is that the legend is using the label descriptions which are quite long, and not the variable names. This is causing the legend to cut off and the graph to be very narrow.

    Using:
    Code:
    graph box Y1skills_academicstudies Y1skills_doctor  Y1feedback_helpful Y1skills_overall, over(treatment) title("Distribution of Reponses")
    I am getting: *please see the post below*
    Last edited by anisha arya; 15 Aug 2024, 05:45.

  • #2
    Here is the link to the graph:
    Attached Files

    Comment


    • #3
      Your question raises issues on three quite different levels.

      Please post images as .png not .gph or .pdf -- as explained at https://www.statalist.org/forums/help#stata 12.3

      If you don't want to see lengthy variable labels, use shorter text.

      Code:
      clonevar academic = Y1skills_academic studies
      label var academic "academic studies"
      Finally, in my opinion a box plot is a very poor plot for data of this kind. Medians, quartiles and other detail are not nearly as informative as histograms or bar charts would be.

      I will post some suggestions shortly.

      Comment


      • #4
        Thank you Nick! That would be very helpful.

        Anisha

        Comment


        • #5
          Here are some possibilities. I used tabplot from the Stata Journal. I doubt that you want to separate treatment as graph box did for your command.

          Many small improvements are possible, e.g. to make clearer what treatment is.

          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input byte(Y1skills_academicstudies Y1skills_doctor Y1feedback_helpful Y1skills_overall treatment)
          2 1 2  4 0
          1 1 1  1 0
          1 1 1  1 0
          3 3 1  4 0
          3 2 1  4 0
          5 5 4  7 0
          2 1 1  3 0
          2 2 1  3 0
          2 2 2  5 0
          1 1 1  1 0
          1 1 3  3 0
          1 2 1  3 0
          1 1 1  1 0
          4 3 2  6 0
          6 6 6  8 0
          3 2 1  3 0
          3 3 1  2 0
          2 1 1  2 0
          2 1 3  3 0
          5 5 6  7 0
          5 5 2  6 0
          4 6 6  4 0
          1 1 2  2 0
          1 1 1  2 0
          6 6 5  7 0
          2 2 6  2 0
          6 5 6  6 0
          2 2 3  3 0
          1 2 1  4 0
          6 3 5  7 0
          6 5 1  6 0
          1 3 1  3 0
          6 5 5  7 0
          3 2 4  5 0
          5 4 5  5 0
          4 1 2  6 0
          2 1 2  2 0
          1 1 2  1 0
          3 3 1  . 0
          7 5 6  8 0
          3 3 2  2 0
          5 5 6  6 0
          5 5 5  6 0
          4 4 5  4 0
          5 3 1  6 0
          2 2 2  1 0
          3 3 5  2 0
          3 3 5  3 0
          5 3 3  4 0
          4 6 3  6 0
          2 2 2  3 0
          1 1 4  1 0
          2 2 1  3 0
          2 2 4  2 0
          1 1 1  2 0
          6 6 6  9 0
          2 2 7  4 0
          6 3 2  8 0
          1 1 1  1 0
          5 2 2  6 0
          2 1 2  3 0
          6 6 6  8 0
          5 5 3  5 0
          5 5 6  6 0
          1 1 1  3 0
          7 5 6  7 0
          2 4 2  3 0
          7 7 6  9 1
          7 7 7  9 1
          5 5 5  6 1
          5 4 3  5 1
          3 3 3  4 1
          3 3 4  7 1
          6 5 7  8 1
          7 6 6  7 1
          5 5 6  7 1
          5 5 5  6 1
          6 6 6  7 1
          6 5 4  7 1
          6 6 3  7 1
          6 5 5  8 1
          6 6 5  7 1
          5 2 7  7 1
          6 6 4  7 1
          6 6 6  7 1
          5 6 3  7 1
          2 2 6  4 1
          7 7 7  9 1
          6 6 7  7 1
          6 6 5  7 1
          6 7 5 10 1
          7 7 7  8 1
          5 4 5  7 1
          7 6 7  8 1
          7 6 6  8 1
          6 5 6  8 1
          5 5 2  5 1
          6 5 6  7 1
          5 5 3  8 1
          6 3 6  8 1
          end
          
          gen id = _n 
          
          reshape long Y1, i(id) j(which) string 
          
          replace which = subinstr(which, "_", " ", .)
          
          tabplot Y1 treatment, by(which, row(1) note("")) horizontal yreverse barw(0.9) ytitle(score) separate(which) showval(offset(0.2))
          Click image for larger version

Name:	skills.png
Views:	1
Size:	37.1 KB
ID:	1761629

          Comment

          Working...
          X