Announcement

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

  • Adding text below the x-axis to group displayed categories

    I am generating a customized plot displaying the 95% confidence interval of my estimate of interest for different heterogeneity results. Each heterogeneity result classifies the data in different ways.

    In the simple example below, the variable "het" refers to the class of heterogeneity and the variable "indicator" refers to specific classifications used within the given class of heterogeneity.

    In the end of the code below, I generate the plot I am interested in. I would like to add some text below the x-axis in order to group different results that belong to the same class of heterogeneity.


    Code:
    clear
    input str20 het het_n effect ci_lower ci_upper
    het1 1 -.1929327   -.2123405   -.1735249 
    het1 2 -.1395898   -.20109   -.0780896
    het2 1 -.2646643   -.297335   -.2319936
    het2 2 -.1605406   -.179301   -.1417801
    het3 1 -.1977444   -.2177585   -.1777303
    het3 2 -.1425936   -.1642216   -.1209657
    het3 3 -.1235394   -.1589206   -.0881581
    het3 4 -.0993597   -.1991288    .0004095
    end
    list, sep(0)
    
    // GENERATING PLOT
    gen x = 1 if het=="het1" & het_n==1
    replace x = 2 if het=="het1" & het_n==2
    replace x = 4 if het=="het2" & het_n==1
    replace x = 5 if het=="het2" & het_n==2
    replace x = 7 if het=="het3" & het_n==1
    replace x = 8 if het=="het3" & het_n==2
    replace x = 9 if het=="het3" & het_n==3
    replace x = 10 if het=="het3" & het_n==4
    
    twoway (rcap ci_upper ci_lower x if het=="het1", lcol(navy)) (scatter effect x if het=="het1", mcol(navy)) ///
    (rcap ci_upper ci_lower x if het=="het2", lcol(cranberry)) (scatter effect x if het=="het2", mcol(cranberry)) ///
    (rcap ci_upper ci_lower x if het=="het3", lcol(brown)) (scatter effect x if het=="het3", mcol(brown)), xscale(range(0 11)) xlabel(1 "type 1" 2 "type 2" 4 "type 1" 5 "type 2" 7 "type 1" 8 "type 2" 9 "type 3" 10 "type 4", noticks labsize(small) angle(vertical)) legend(off) xtitle("") ytitle("Policy effect") yscale(titlegap(2)) ylabel(, labsize(small)) yline(0, lcolor(black) lpattern(dash)) graphregion(color(white))

    I would like to add below the x-axis the respective class of heterogeneity under consideration. In other words, I would like to add the text "Heterogeneity 1" below the first two groups in the x-label, the text "Heterogeneity 2" below the following two groups, and the text "Heterogeneity 3" below the last four groups in the x-label.


  • #2
    Code:
    clear
    input str20 het het_n effect ci_lower ci_upper
    het1 1 -.1929327   -.2123405   -.1735249 
    het1 2 -.1395898   -.20109   -.0780896
    het2 1 -.2646643   -.297335   -.2319936
    het2 2 -.1605406   -.179301   -.1417801
    het3 1 -.1977444   -.2177585   -.1777303
    het3 2 -.1425936   -.1642216   -.1209657
    het3 3 -.1235394   -.1589206   -.0881581
    het3 4 -.0993597   -.1991288    .0004095
    end
    list, sep(0)
    
    // GENERATING PLOT
    gen x = 1 if het=="het1" & het_n==1
    replace x = 2 if het=="het1" & het_n==2
    replace x = 4 if het=="het2" & het_n==1
    replace x = 5 if het=="het2" & het_n==2
    replace x = 7 if het=="het3" & het_n==1
    replace x = 8 if het=="het3" & het_n==2
    replace x = 9 if het=="het3" & het_n==3
    replace x = 10 if het=="het3" & het_n==4
    
    twoway (rcap ci_upper ci_lower x if het=="het1", lcol(navy)) (scatter effect x if het=="het1", mcol(navy)) ///
    (rcap ci_upper ci_lower x if het=="het2", lcol(cranberry)) (scatter effect x if het=="het2", mcol(cranberry)) ///
    (rcap ci_upper ci_lower x if het=="het3", lcol(brown)) (scatter effect x if het=="het3", mcol(brown)), xscale(range(0 11)) xlabel(1 "type 1" 2 "type 2" 4 "type 1" 5 "type 2" 7 "type 1" 8 "type 2" 9 "type 3" 10 "type 4", noticks labsize(small)) legend(off) xtitle("") ytitle("Policy effect") yscale(titlegap(2)) ylabel(, labsize(small)) yline(0, lcolor(black) lpattern(dash)) graphregion(color(white)) ///
    xmla(1.5 "Heterogeneity 1" 4.5 "Heterogeneity 2" 8.5 "Heterogeneity 3", tlc(none) tlength(*6) labsize(medlarge))
    See also https://journals.sagepub.com/doi/pdf...36867X19874264

    Click image for larger version

Name:	hetero.png
Views:	1
Size:	29.4 KB
ID:	1722045

    Comment


    • #3
      To spell it out, I am using xmla() for the larger text labels. They are called minor labels, but they are only minor, meaning small, by default. It would be entirely possible to use xmla() for the smaller labels and xla() for the larger labels. The point is that you can have two sets of axis labels, which is not only useful but also essential when you want different label sizes, as is both possible and cogent in this case.

      I see no point in making your original labels vertical. Vertical or sloping text on graphs is an example of what has been called giraffe graphics, in allusion to the fact the giraffes move their necks up and down and every which way. Choosing vertical or sloping text is only necessary when horizontal text just won't work.

      Comment

      Working...
      X