Announcement

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

  • Cannot add axis scale without smashing last catplot in graph combine

    Click image for larger version

Name:	Screen Shot 2020-03-09 at 10.47.49 AM.png
Views:	2
Size:	63.1 KB
ID:	1540464
    I am attempting to combine catplot graphs which have a common categorical response. When I include an axis on the last graphic (omitting ysc(off) in the last catplot code for q14_r1), it collapses the graphic and I am unable to adjust this.

    If I do not include an axis in the last graphic (including ysc(off) in the last catplot code for q14_r1), I am unable to add one in the Stata graph editor. I have tried both grc1leg and gr combine. Please see my sample data and code below.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(q13_r3 q13_r2 q12_r1 q12_r2 q14_r1)
    3 3 3 3 5
    1 1 2 2 1
    4 3 4 4 4
    5 5 4 4 3
    4 3 4 4 4
    4 2 3 4 2
    3 4 2 3 2
    3 4 3 4 2
    4 4 4 4 3
    2 2 3 3 2
    3 1 5 3 3
    3 4 3 4 4
    4 4 3 3 2
    5 3 5 4 1
    4 4 4 4 4
    3 3 2 4 4
    4 4 4 4 3
    3 4 4 4 3
    4 4 3 3 3
    4 4 3 4 3
    3 5 3 4 4
    3 5 5 5 1
    5 4 2 3 1
    4 4 2 2 5
    3 3 3 3 2
    5 5 5 5 1
    4 4 5 5 5
    4 4 3 3 1
    3 4 4 3 2
    3 5 2 4 1
    4 4 4 4 3
    2 2 2 2 2
    5 5 5 5 1
    4 5 4 5 2
    4 4 4 4 3
    5 5 5 5 5
    5 5 5 5 4
    3 4 4 4 2
    4 2 2 2 4
    5 5 4 4 3
    2 2 4 3 3
    2 3 3 4 1
    3 1 2 3 4
    4 2 3 3 1
    5 4 4 4 1
    3 3 4 4 2
    1 1 1 4 5
    4 3 2 2 4
    5 1 3 2 2
    4 4 4 4 3
    4 4 4 4 2
    3 4 4 4 3
    1 1 1 1 5
    4 3 4 4 4
    4 3 4 4 5
    4 4 4 3 1
    5 3 3 3 3
    2 3 4 4 4
    4 1 3 3 5
    . . . . .
    1 3 2 4 3
    5 5 4 4 1
    4 5 5 5 5
    4 4 5 4 3
    4 4 4 4 2
    3 4 4 3 2
    4 5 4 5 2
    4 4 5 5 3
    5 4 4 4 3
    4 4 4 4 3
    5 5 5 5 4
    5 4 5 4 4
    4 4 3 3 3
    4 4 3 4 3
    4 1 4 5 4
    3 1 4 4 3
    4 5 4 4 2
    4 3 5 5 3
    4 4 4 4 5
    2 1 2 3 3
    4 4 5 4 5
    3 2 5 5 3
    4 4 4 4 3
    4 3 3 3 3
    3 5 4 3 3
    4 1 3 3 4
    4 3 5 4 3
    4 2 5 4 4
    2 4 4 4 5
    3 3 5 5 3
    4 2 4 4 2
    4 4 4 3 3
    5 4 4 4 2
    2 2 2 2 2
    4 3 4 5 2
    3 5 5 5 1
    3 3 4 4 5
    3 4 4 4 4
    . . . . .
    3 4 4 4 3
    end
    label values q12_r1 agree_alt
    label values q12_r2 agree_alt
    label values q13_r2 agree_alt
    label values q13_r3 agree_alt
    label values q14_r1 agree_alt
    label def agree_alt 1 "Strongly Disagree", modify
    label def agree_alt 2 "Disagree", modify
    label def agree_alt 3 "Neutral", modify
    label def agree_alt 4 "Agree", modify
    label def agree_alt 5 "Strongly Agree", modify
    
    foreach j in q13_r3 q13_r2 q12_r1 q12_r2 {
        local label : var label `j'
    catplot `j', percent var1opts(label(labsize(small))) ysc(off) ///
    ytitle(" ", size(small)) stack graphregion(color(white))  ///
    title("`label'" , span size(medium) color(black)) ///
    blabel(bar, pos(inside) format(%4.1f) size(vsmall)) ///
    l1title("") intensity(25) asyvars ///
    bar(1, color(maroon) fintensity(inten70)) ///
    bar(2, color(maroon) fintensity(inten50)) ///
    bar(3, color(gray) fintensity(inten40)) ///
    bar(4, color(dkgreen) fintensity(inten50)) ///
    bar(5, color(dkgreen) fintensity(inten70)) ///
    legend(off) ///
    name(g`j', replace)
    }
    
    local x : var label q14_r1
    catplot q14_r1, percent var1opts(label(labsize(small))) ///
    ytitle(" ", size(small)) stack graphregion(color(white)) ///
    title("`x'" , span size(medium) color(black)) ///
    blabel(bar, pos(inside) format(%4.1f) size(vsmall)) ///
    l1title("") intensity(25) asyvars ///
    bar(1, color(maroon) fintensity(inten70)) ///
    bar(2, color(maroon) fintensity(inten50)) ///
    bar(3, color(gray) fintensity(inten40)) ///
    bar(4, color(dkgreen) fintensity(inten50)) ///
    bar(5, color(dkgreen) fintensity(inten70)) ///
    legend(rows(1) stack size(vsmall) order() symplacement(center)) ///
    name(gq14_r1, replace)
    
    grc1leg gq13_r3 gq13_r2 gq12_r1 gq12_r2 gq14_r1, leg(gq14_r1) ///
        ycommon cols(1) graphregion(margin(large) color(white)) ///
        imargin(0 0 0 0)
    
    gr combine gq13_r3 gq13_r2 gq12_r1 gq12_r2 gq14_r1, colfirst ///
        cols(1) imargin() title("") ///
        graphregion(color(white))
    Attached Files

  • #2
    http://www.catb.org/jargon/html/D/Do...hat-then-.html

    I'd restructure the data so that you get one plot, not several that you then you have to (try to) mash together. This is schematic but I think solves your major problem. In your design the variable labels have disappeared, which is surely unwanted. If you gave the variable labels, they would be used automatically in the designs below, although they need to be concise.

    This code follows on from your data example.

    catplot is from SSC (as you are asked to explain: FAQ Advice #12). Similarly, tabplot used here is from the Stata Journal.

    Code:
    gen id = _n 
    
    reshape long q , i(id) j(which) string 
    
    label val q agree_alt 
    
    catplot q which , asyvars stack percent(which) ///
    bar(1, color(maroon) fintensity(inten70)) ///
    bar(2, color(maroon) fintensity(inten50)) ///
    bar(3, color(gray) fintensity(inten40)) ///
    bar(4, color(dkgreen) fintensity(inten50)) ///
    bar(5, color(dkgreen) fintensity(inten70)) ///
    name(G1, replace) 
    
    tabplot q which, percent(which) ytitle("") xtitle("") showval name(G2, replace) subtitle(%) ///
    separate(q) bar1(color(maroon) fintensity(inten70)) ///
    bar2(color(maroon) fintensity(inten50)) ///
    bar3(color(gray) fintensity(inten40)) ///
    bar4(color(dkgreen) fintensity(inten50)) ///
    bar5(color(dkgreen) fintensity(inten70))
    Click image for larger version

Name:	alice1.png
Views:	1
Size:	21.6 KB
ID:	1540472
    Click image for larger version

Name:	alice2.png
Views:	1
Size:	21.1 KB
ID:	1540473

    Comment


    • #3
      Correction: Variable labels would disappear on reshape. You'd need to introduce them as value labels.

      Comment


      • #4
        Thanks for your reply, Nick. My apologies, I'd omitted the variable labels intentionally due to the confidentially requirements of the data with which I am working and omitted an important detail: I am using catplot from SSC in Stata 14.2.

        Is there any way to apply the variable labels above the bars? The responses are from patient surveys, and the questions asked are quite difficult to refine to short phrases which will fit on an axis even if using angle() options. For example, one variable label is similar to "I would like my provider to send follow-up instructions using my preferred communication channel." Even "Follow-up instructions via preferred channel" is quite a long variable name. I'd chosen the graph combine approach partially because of this attribute of the nature of the variables.

        Comment


        • #5
          This was the best I could see with a bit of play. Don't ask me to like it!


          Code:
          gen id = _n 
          
          rename q* q#, addnumber 
          
          reshape long q , i(id) j(which) 
          
          label def which 1 "example of a long description" 
          label val which which 
          
          label val q agree_alt 
          
          catplot q, by(which, col(1) note("") legend(pos(3))) percent(which) ytitle("%") name(G2, replace) ///
          asyvars stack recast(hbar) bar(1, color(maroon) fintensity(inten70)) ///
          bar(2, color(maroon) fintensity(inten50)) ///
          bar(3, color(gray) fintensity(inten40)) ///
          bar(4, color(dkgreen) fintensity(inten50)) ///
          bar(5, color(dkgreen) fintensity(inten70)) legend(col(1))
          Click image for larger version

Name:	alice3.png
Views:	1
Size:	21.0 KB
ID:	1540613

          Comment


          • #6
            You can get more space with

            Code:
            legend(col(1) symxsize(small))

            Comment

            Working...
            X