Announcement

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

  • Suppressing Repeated Categorical Axis Labels in by-graphs

    Hi, I would like to suppress the categorical axis labels in the right-hand graph in a by-graph like:
    Code:
    . sysuse auto2
    . graph dot price , by(foreign, row(1)) over(rep78) name(repeated, replace)
    I've worked my way through the suboptions of the by-option, like
    noiylabel / noixlabel, but none of them works for categorical axes. What I typically do in such cases is to draw separate graphs and then combine them, suppressing the categorical axis in one of the original graphs. This gets me were I want, but it is still an awkward solution for many reasons. For the above toy example, this approach would entail, at a minimum,

    Code:
    . insobs 2
    . replace foreign=1 in -2/l
    . replace rep78=1 in -2
    . replace rep78=2 in l
    . graph dot price if foreign==0, name(for0, replace) over(rep78)
    . graph dot price if foreign==1, name(for1, replace) graphregion(margin(r 20)) ylabel(0(2000)8000) over(rep78, label(nolabels))
    . graph combine for0 for1 , row(1) name(fixed, replace)


    This can get much more complicated for real-world graphs with many subgraphs. Does anyone know an easier / better solution than the above?

    Best,
    Daniel




  • #2
    One way I made progress on this:


    Code:
    sysuse auto2, clear 
    set scheme s1color 
    egen mean = mean(price), by(foreign rep78)
    label var mean "Mean price (USD)"
    twoway dot mean rep78, by(foreign, note("")) horizontal yla(, ang(h))

    Comment


    • #3
      Thanks Nick, good point that manually assigning coordinates and axis labels and using a graph twoway statement also does the job. However, this approach too can become quite tedious very quickly, for example, when categories are nested, as in:

      Code:
      . sysuse auto2, clear
      . gen longcar = (length>=200)
      . label define LONGCAR 0 "Short cars" 1 "Long cars"
      . label values longcar LONGCAR
      . graph dot price , by(foreign, row(1)) over(rep78) over(longcar, lab(ang(vert))) name(nested, replace) scheme(s2color)
      so it would still be nice to just have an option that switches off the repetition of categorical axes.

      Comment


      • #4
        Originally posted by Daniel Schneider View Post
        so it would still be nice to just have an option that switches off the repetition of categorical axes.
        I have been longing for this too, but I don't think we have a choice when using the 'by' option. I solve it with loop and then combine as you mentioned.
        Roman

        Comment


        • #5
          I don't have a solution for that. I don't often plot means and nothing else, so I have been bitten by this myself.

          Comment


          • #6
            Thanks both for your input. If I don't receive any other suggestions, I'll make an entry in the Wishlist for Stata 18 about adding a suitable suboption to the by-option.

            Comment


            • #7
              Invisible value labels as in #3 of https://www.statalist.org/forums/for...t-graph-y-axis are one way. But that involves some level of data manipulation.

              Comment


              • #8
                #5 should have ended

                so I have not been bitten by this myself

                Comment


                • #9
                  Originally posted by Andrew Musau View Post
                  Invisible value labels as in #3 of https://www.statalist.org/forums/for...t-graph-y-axis are one way. But that involves some level of data manipulation.
                  Thanks Andrew for pointing directly and indirectly to threads where the same or similar questions were asked. I had overlooked those. The solution proposed there is also a little bit involved, so I think we still have the case for asking for a new option.

                  Comment


                  • #10
                    Originally posted by Daniel Schneider View Post
                    The solution proposed there is also a little bit involved, so I think we still have the case for asking for a new option.
                    I agree and would welcome such an option.

                    Comment


                    • #11
                      Stata's nested structure of options are tedious and heavy bulk themselves. However, I'm not sure if it is practicer of The Grammar of Graphics and the precursor of R. In fact, Stata allows you to modify almost everything details of your graph.

                      Code:
                      ggplot(data=mtcars, aes(x=hp, y=mpg, shape=cyl, color=cyl)) +
                            geom_point(size=3) +
                            facet_grid(am~vs) +
                            labs(title="Automobile Data by Engine Type", x="Horsepower", y="Miles Per Gallon")

                      Comment


                      • #12
                        How to remove y-axis?
                        Code:
                        * Example generated by -dataex-. For more info, type help dataex
                        clear
                        input float(t_emp stub1 stub2 stub3)
                        0  38.73769  28.22416 33.038147
                        1  4.959128  29.31694  65.72393
                        2 11.304404  27.83145  60.86414
                        3   14.8701 35.657204   49.4727
                        4  50.14215  25.36735   24.4905
                        end
                        label values t_emp t_emp
                        label def t_emp 0 "Total", modify
                        label def t_emp 1 "Grande", modify
                        label def t_emp 2 "Mediana", modify
                        label def t_emp 3 "Pequeña", modify
                        label def t_emp 4 "Micro", modify
                        
                        
                        *** ================================================== ================
                        *** Scheme :
                        set scheme cleanplots
                        *** ================================================== ================
                        
                        gr bar stub1 stub2 stub3 , over(t_emp) stack bar(1, color(69 123 157)) bar(2, color(230 57 70)) bar(3, color(168 218 220)) blabel(bar ,position(center) format(%12,1f)) title("{bf:Empresas según modalidad de trabajo adoptada}") leg(pos(6) order(1 "Sólo trabajo presencial" 2 "Sólo trabajo remoto" 3 "Trabajo mixto (presencial y remoto)") rows(1)) scheme(cleanplots)

                        Comment


                        • #13
                          Your question does not exactly follow the title of this thread. In future, start a new thread. Include the option:

                          Code:
                          ylab(none)

                          Comment


                          • #14
                            Ok. Thank you very much Andrew Musau.

                            Comment

                            Working...
                            X