Announcement

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

  • Axis titles with catplot & by option

    Hello

    I am using catplot to plot a categorical outcome variable over time for 2 treatment groups.

    If I display the graphs over 2 columns, is there a way to show only the axis tile (l1title) for the first graph?

    So far I have:

    Code:
    catplot catvar week, by(randgroup, col(2) note(""))                    ///
         percent(week randgroup) asyvars stack                             ///
         ytitle("Proportion (%)")                                        ///
         l1title("Week")                                                ///
         legend(cols(3))
    Where "Week" displays as the axis title for both graphs - can I keep it only for the graph in the first column? (& retain the spacing so that both graphs are the same size)

    Thanks!
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	20.7 KB
ID:	1661394


  • #2
    catplot is from SSC, as you are asked to explain (FAQ Advice #12). You can remove that title in the Graph Editor but I can't find a way to do it using syntax.

    This code produces a reproducible example of a similar graph, given the absence of a data example in #1, should anyone have a better idea. I've corrected "Proportion" to "Percent".

    Code:
    sysuse auto, clear 
    
    gen catvar = cond(mpg < 20, 1, cond(mpg < 35, 2, 3))
    label def catvar 1 awful 2 adequate 3 admirable 
    label val catvar catvar
    rename (foreign rep78) (randgroup week)
    
    catplot catvar week, by(randgroup, col(2) note(""))                    ///
         percent(week randgroup) asyvars stack                             ///
         ytitle("Percent (%)")                                        ///
         l1title("Week")                                                ///
         legend(cols(3)) scheme(s1color)
    
    

    Comment


    • #3
      catplot is from SSC, as you are asked to explain (FAQ Advice #12). You need to put the title within -by()-

      Code:
       catplot catvar week, by(randgroup, col(2) note("") l1title("Week"))   ///    
           percent(week randgroup) asyvars stack                            ///      
           ytitle("Proportion (%)")                                        ///    
           legend(cols(3))
      NB. Crossed with #2.
      Last edited by Andrew Musau; 25 Apr 2022, 08:19.

      Comment


      • #4
        Andrew Musau's solution is clearly better!

        Comment

        Working...
        X