Announcement

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

  • Combine graphs with common y-axis

    I am trying to combine several graphs using -combine- and a single row whereby I want to have the y-axis labels only on the leftmost graph.

    Using -combine- with only two graphs works as intended (although I would like to have the gap between the graphs somewhat smaller):
    Code:
    graph combine vtheflyp vrobblyp, ycommon rows(1) iscale(*1.1) ///
          name("combined2", replace)
    produces the following graph:
    Click image for larger version

Name:	combined_2.png
Views:	1
Size:	164.7 KB
ID:	1775300

    However, if I try to combine three graphs the same way, the scaling of the first graph is smaller than the scaling of the subsequent graphs:
    Code:
    graph combine vtheflyp vrobblyp vassalyp, ycommon rows(1) iscale(*.90) ///
          name("combined", replace)
    which produces:
    Click image for larger version

Name:	combined.png
Views:	1
Size:	206.1 KB
ID:	1775301

    Is there a possibility to combine several graphs with a common y-axis and y-axis labels only for the leftmost graph?

  • #2
    Perhaps I should have explained that I produced the second and third graph with the option yscale(off), see https://www.statalist.org/forums/for...ng-same-y-axis

    Comment


    • #3
      A longer way round, but often a solution, is to recast the problem using a by() option. https://journals.sagepub.com/doi/pdf...36867X20976341

      Comment


      • #4
        Nick Cox : Thanks, using the by() option the graph looks much better. However, now I have the problem (a) of how to add lines for the mean per graph -- in my previous graphs I did use xline(`=scalar(mean_vthef)') etc. for each graph -- and (b) of how to control the formatting of the titles "Personal Theft" etc., e.g. I would like to have no shaded box and a different size. One can debate whether shaded boxes wouldn't be better than no boxes, but the character size is a problem.

        To create the graph I used
        Code:
        twoway (rcap ll ul ncountrys, sort msize(medsmall) lcolor(maroon) hor) ///
               (dot b ncountrys, sort fcolor(gs12) mcolor(navy) msymbol(circle) hor), ///
               ylabel(1(1)25, valuelabels labsize(8-pt)) ytitle("") ///
               yscale(reverse) xlabel(, grid glcolor(gs15) labsize(small)) ///
                xtitle("% Last Year Prevalence {&plusmn} 95%-CI", size(7pt)) ///
               yline(3, lcolor(gray) lpat(dot)) ///
               yline(8, lcolor(gray) lpat(dot)) ///
               yline(14, lcolor(gray) lpat(dot)) ///
               yline(20, lcolor(gray) lpat(dot)) ///
               aspectratio(1.5) ///
               scheme(cleanplots) legend(off) name("combined_v2", replace) ///
               by(otype, rows(1) iscale(*.9) xrescale note("") legend(off))
        which produced
        Click image for larger version

Name:	combined_v2.png
Views:	1
Size:	205.1 KB
ID:	1775311

        Last edited by Dirk Enzmann; 03 Apr 2025, 12:26.

        Comment


        • #5
          It will be easier to suggest code if you provide a reproducible example, which doesn’t necessarily have to use your actual data.

          Comment


          • #6
            Here a data example for the graphs in #1 (different variables and labels):
            Code:
            * Example generated by -dataex-. For more info, type help dataex
            clear
            input double(otype_1_b otype_1_ll otype_1_ul otype_2_b otype_2_ll otype_2_ul otype_3_b otype_3_ll otype_3_ul)
            1.8232662677764893 1.2744916677474976 2.6021058559417725 2.2162022590637207 1.6103087663650513  3.043017864227295 16.107105255126953 14.363504409790039 18.017831802368164
             2.354274272918701 1.8997215032577515  2.914358139038086 2.7415568828582764  2.247854471206665 3.3399875164031982 11.198442459106445 10.162979125976563 12.324931144714355
            1.9480551481246948 1.1691687107086182 3.2288742065429688  2.276259660720825 1.4006472826004028 3.6788361072540283 12.495499610900879 10.274386405944824  15.11587905883789
              1.18836510181427  .7556593418121338 1.8641927242279053 1.5470795631408691 1.0408555269241333 2.2938008308410645 10.005953788757324  8.606156349182129 11.604519844055176
             2.804978847503662 1.9012080430984497  4.120327472686768  5.755327224731445 4.2833147048950195  7.692558765411377 14.711297988891602 12.906121253967285 16.720491409301758
            2.5819835662841797 1.8128925561904907 3.6651699542999268 2.3652873039245605 1.6184827089309692 3.4446194171905518 13.343868255615234 11.521143913269043 15.404752731323242
            1.6282821893692017 1.0509626865386963 2.5146775245666504  2.789125919342041 1.9968457221984863 3.8832998275756836 10.134563446044922  8.534324645996094 11.995504379272461
             2.465771436691284  1.726130723953247 3.5110225677490234 2.5495307445526123 2.0424842834472656 3.1783673763275146 13.752142906188965 11.857715606689453 15.894651412963867
            1.0368071794509888  .5723732113838196 1.8709995746612549  2.524855136871338 1.6981732845306396 3.7386653423309326  16.70213508605957   14.7279634475708   18.8823299407959
             3.835354804992676   2.61684513092041  5.588690757751465 3.9136362075805664  2.763946294784546  5.514429569244385  18.36253547668457 15.617354393005371  21.46749496459961
            2.7553815841674805  2.096219301223755 3.6141674518585205 3.6556622982025146  2.891890525817871  4.611573219299316 14.887200355529785 13.332172393798828 16.588886260986328
             3.482848882675171 2.7548253536224365  4.394574165344238 2.8116471767425537 2.1764423847198486   3.62536883354187 18.207521438598633 16.500612258911133  20.04860496520996
            2.9384758472442627 1.9276129007339478   4.45536470413208  6.897892475128174  5.288421630859375  8.950895309448242  21.56774139404297 18.421165466308594 25.086511611938477
             4.120311260223389 3.2498581409454346  5.211350917816162  7.247931957244873   6.16160774230957  8.508415222167969 20.616485595703125 18.789337158203125 22.571929931640625
              4.69985818862915 3.8406169414520264  5.739858627319336  4.250799655914307  3.443373918533325  5.237286567687988 22.709247589111328 20.865633010864258  24.66498565673828
             3.604170799255371 3.1911513805389404  4.068399429321289  3.497159481048584 3.0947906970977783 3.9497101306915283  24.63816261291504 23.667694091796875 25.635061264038086
            3.0504472255706787  2.078294038772583  4.456643581390381 3.3864657878875732  2.538670063018799  4.504300117492676 15.528800010681152 13.453604698181152 17.858041763305664
             3.702775239944458 2.9151315689086914  4.692945957183838  5.779311180114746 4.7802252769470215  6.971920967102051 18.792972564697266 17.010204315185547   20.7159481048584
             3.055663824081421 2.2774438858032227  4.088681221008301  6.591779708862305 5.4151811599731445  8.002397537231445 23.582414627075195 21.423551559448242  25.88715362548828
             4.522955894470215    3.7177894115448  5.492550849914551  6.519256114959717  5.550937175750732     7.642822265625  22.67756462097168  20.90726661682129 24.551227569580078
            3.6960561275482178 2.9255692958831787  4.659719944000244 11.913434982299805 10.545015335083008 13.432767868041992 23.789976119995117  21.88181495666504 25.809558868408203
            end
            label values ncountrys ncountrys
            label def ncountrys 1 "ncountry 01", modify
            label def ncountrys 2 "ncountry 02", modify
            label def ncountrys 4 "ncountry 03", modify
            label def ncountrys 5 "ncountry 04", modify
            label def ncountrys 6 "ncountry 05", modify
            label def ncountrys 7 "ncountry 06", modify
            label def ncountrys 9 "ncountry 07", modify
            label def ncountrys 10 "ncountry 08", modify
            label def ncountrys 11 "ncountry 09", modify
            label def ncountrys 12 "ncountry 10", modify
            label def ncountrys 13 "ncountry 11", modify
            label def ncountrys 15 "ncountry 12", modify
            label def ncountrys 16 "ncountry 13", modify
            label def ncountrys 17 "ncountry 14", modify
            label def ncountrys 18 "ncountry 15", modify
            label def ncountrys 19 "ncountry 16", modify
            label def ncountrys 21 "ncountry 17", modify
            label def ncountrys 22 "ncountry 18", modify
            label def ncountrys 23 "ncountry 19", modify
            label def ncountrys 24 "ncountry 20", modify
            label def ncountrys 25 "ncountry 21", modify
            
            scalar mean_otype1 =  2.9152774810791
            scalar mean_otype2 =  4.3403916358948
            scalar mean_otype3 = 17.3048191070557
            and the syntax to create the single graphs for these data (which subsequenty I tried to combine with combine):

            Code:
            twoway (rcap otype_1_ll otype_1_ul ncountrys, sort msize(medsmall) lcolor(maroon) hor) ///
                   (dot otype_1 ncountrys, sort fcolor(gs12) mcolor(navy) msymbol(circle) hor), ///
                   ylabel(1(1)25, valuelabels labsize(8-pt)) ytitle("") ///
                   yscale(reverse) xlabel(, grid glcolor(gs15) labsize(small)) ///
                    xtitle("% Last Year Prevalence {&plusmn} 95%-CI", size(small)) ///
                   xline(`=scalar(mean_otype_1)', lcolor(gray) lpat(dash)) ///
                   yline(3, lcolor(gray) lpat(dot)) ///
                   yline(8, lcolor(gray) lpat(dot)) ///
                   yline(14, lcolor(gray) lpat(dot)) ///
                   yline(20, lcolor(gray) lpat(dot)) ///
                   title("OType 1", size(small) span) ///
                   aspectratio(1.5) ///
                   scheme(cleanplots) legend(off) name("otype_1", replace)
            graph export "${outp}vtheflyp.png", replace
                  
            twoway (rcap otype_2_ll otype_2_ul ncountrys, sort msize(medsmall) lcolor(maroon) hor) ///
                   (dot otype_2 ncountrys, sort fcolor(gs12) mcolor(navy) msymbol(circle) hor), ///
                   ylabel(1(1)25, valuelabels labsize(8-pt)) ytitle("") ///
                   yscale(reverse off) xlabel(, grid glcolor(gs15) labsize(small)) ///
                    xtitle("% Last Year Prevalence {&plusmn} 95%-CI", size(small)) ///
                   xline(`=scalar(mean_otype_2)', lcolor(gray) lpat(dash)) ///
                   yline(3, lcolor(gray) lpat(dot)) ///
                   yline(8, lcolor(gray) lpat(dot)) ///
                   yline(14, lcolor(gray) lpat(dot)) ///
                   yline(20, lcolor(gray) lpat(dot)) ///
                   title("OType 2", size(small) span) ///
                   aspectratio(1.5) ///
                   scheme(cleanplots) legend(off) name("otype_2", replace)
            
            twoway (rcap otype_3_ll otype_3_ul ncountrys, sort msize(medsmall) lcolor(maroon) hor) ///
                   (dot otype_3 ncountrys, sort fcolor(gs12) mcolor(navy) msymbol(circle) hor), ///
                   ylabel(1(1)25, valuelabels labsize(8-pt)) ytitle("") ///
                   yscale(reverse off) xlabel(, grid glcolor(gs15) labsize(small)) ///
                    xtitle("% Last Year Prevalence {&plusmn} 95%-CI", size(small)) ///
                   xline(`=scalar(mean_otype_3)', lcolor(gray) lpat(dash)) ///
                   yline(3, lcolor(gray) lpat(dot)) ///
                   yline(8, lcolor(gray) lpat(dot)) ///
                   yline(14, lcolor(gray) lpat(dot)) ///
                   yline(20, lcolor(gray) lpat(dot)) ///
                   title("OType 3", size(small) span) ///
                   aspectratio(1.5) ///
                   scheme(cleanplots) legend(off) name("otype_3", replace)
            And here a data example for the graph in #4 (different variable names and labels):
            Code:
            * Example generated by -dataex-. For more info, type help dataex
            clear
            input float otype long ncountrys double(b ll ul)
            1  1 1.8232662677764893 1.2744916677474976 2.6021058559417725
            1  2  2.354274272918701 1.8997215032577515  2.914358139038086
            1  4 1.9480551481246948 1.1691687107086182 3.2288742065429688
            1  5   1.18836510181427  .7556593418121338 1.8641927242279053
            1  6  2.804978847503662 1.9012080430984497  4.120327472686768
            1  7 2.5819835662841797 1.8128925561904907 3.6651699542999268
            1  9 1.6282821893692017 1.0509626865386963 2.5146775245666504
            1 10  2.465771436691284  1.726130723953247 3.5110225677490234
            1 11 1.0368071794509888  .5723732113838196 1.8709995746612549
            1 12  3.835354804992676   2.61684513092041  5.588690757751465
            1 13 2.7553815841674805  2.096219301223755 3.6141674518585205
            1 15  3.482848882675171 2.7548253536224365  4.394574165344238
            1 16 2.9384758472442627 1.9276129007339478   4.45536470413208
            1 17  4.120311260223389 3.2498581409454346  5.211350917816162
            1 18   4.69985818862915 3.8406169414520264  5.739858627319336
            1 19  3.604170799255371 3.1911513805389404  4.068399429321289
            1 21 3.0504472255706787  2.078294038772583  4.456643581390381
            1 22  3.702775239944458 2.9151315689086914  4.692945957183838
            1 23  3.055663824081421 2.2774438858032227  4.088681221008301
            1 24  4.522955894470215    3.7177894115448  5.492550849914551
            1 25 3.6960561275482178 2.9255692958831787  4.659719944000244
            2  1 2.2162022590637207 1.6103087663650513  3.043017864227295
            2  2 2.7415568828582764  2.247854471206665 3.3399875164031982
            2  4  2.276259660720825 1.4006472826004028 3.6788361072540283
            2  5 1.5470795631408691 1.0408555269241333 2.2938008308410645
            2  6  5.755327224731445 4.2833147048950195  7.692558765411377
            2  7 2.3652873039245605 1.6184827089309692 3.4446194171905518
            2  9  2.789125919342041 1.9968457221984863 3.8832998275756836
            2 10 2.5495307445526123 2.0424842834472656 3.1783673763275146
            2 11  2.524855136871338 1.6981732845306396 3.7386653423309326
            2 12 3.9136362075805664  2.763946294784546  5.514429569244385
            2 13 3.6556622982025146  2.891890525817871  4.611573219299316
            2 15 2.8116471767425537 2.1764423847198486   3.62536883354187
            2 16  6.897892475128174  5.288421630859375  8.950895309448242
            2 17  7.247931957244873   6.16160774230957  8.508415222167969
            2 18  4.250799655914307  3.443373918533325  5.237286567687988
            2 19  3.497159481048584 3.0947906970977783 3.9497101306915283
            2 21 3.3864657878875732  2.538670063018799  4.504300117492676
            2 22  5.779311180114746 4.7802252769470215  6.971920967102051
            2 23  6.591779708862305 5.4151811599731445  8.002397537231445
            2 24  6.519256114959717  5.550937175750732     7.642822265625
            2 25 11.913434982299805 10.545015335083008 13.432767868041992
            4  1 16.107105255126953 14.363504409790039 18.017831802368164
            4  2 11.198442459106445 10.162979125976563 12.324931144714355
            4  4 12.495499610900879 10.274386405944824  15.11587905883789
            4  5 10.005953788757324  8.606156349182129 11.604519844055176
            4  6 14.711297988891602 12.906121253967285 16.720491409301758
            4  7 13.343868255615234 11.521143913269043 15.404752731323242
            4  9 10.134563446044922  8.534324645996094 11.995504379272461
            4 10 13.752142906188965 11.857715606689453 15.894651412963867
            4 11  16.70213508605957   14.7279634475708   18.8823299407959
            4 12  18.36253547668457 15.617354393005371  21.46749496459961
            4 13 14.887200355529785 13.332172393798828 16.588886260986328
            4 15 18.207521438598633 16.500612258911133  20.04860496520996
            4 16  21.56774139404297 18.421165466308594 25.086511611938477
            4 17 20.616485595703125 18.789337158203125 22.571929931640625
            4 18 22.709247589111328 20.865633010864258  24.66498565673828
            4 19  24.63816261291504 23.667694091796875 25.635061264038086
            4 21 15.528800010681152 13.453604698181152 17.858041763305664
            4 22 18.792972564697266 17.010204315185547   20.7159481048584
            4 23 23.582414627075195 21.423551559448242  25.88715362548828
            4 24  22.67756462097168  20.90726661682129 24.551227569580078
            4 25 23.789976119995117  21.88181495666504 25.809558868408203
            end
            label values otype otype
            label def otype 1 "OType 1", modify
            label def otype 2 "OType 2", modify
            label def otype 3 "OType 3", modify
            label values ncountrys ncountrys
            label def ncountrys 1 "ncountry 01", modify
            label def ncountrys 2 "ncountry 02", modify
            label def ncountrys 4 "ncountry 03", modify
            label def ncountrys 5 "ncountry 04", modify
            label def ncountrys 6 "ncountry 05", modify
            label def ncountrys 7 "ncountry 06", modify
            label def ncountrys 9 "ncountry 07", modify
            label def ncountrys 10 "ncountry 08", modify
            label def ncountrys 11 "ncountry 09", modify
            label def ncountrys 12 "ncountry 10", modify
            label def ncountrys 13 "ncountry 11", modify
            label def ncountrys 15 "ncountry 12", modify
            label def ncountrys 16 "ncountry 13", modify
            label def ncountrys 17 "ncountry 14", modify
            label def ncountrys 18 "ncountry 15", modify
            label def ncountrys 19 "ncountry 16", modify
            label def ncountrys 21 "ncountry 17", modify
            label def ncountrys 22 "ncountry 18", modify
            label def ncountrys 23 "ncountry 19", modify
            label def ncountrys 24 "ncountry 20", modify
            label def ncountrys 25 "ncountry 21", modify
            
            scalar mean_otype_1 =  2.9152774810791
            scalar mean_otype_2 =  4.3403916358948
            scalar mean_otype_3 = 17.3048191070557
            with the code to produce the graph in #4:
            Code:
            twoway (rcap ll ul ncountrys, sort msize(medsmall) lcolor(maroon) hor) ///
                   (dot b ncountrys, sort fcolor(gs12) mcolor(navy) msymbol(circle) hor), ///
                   ylabel(1(1)25, valuelabels labsize(8pt)) ytitle("") ///
                   yscale(reverse) xlabel(, grid glcolor(gs15) labsize(small)) ///
                    xtitle("% Last Year Prevalence {&plusmn} 95%-CI", size(6pt)) ///
                   yline(3, lcolor(gray) lpat(dot)) ///
                   yline(8, lcolor(gray) lpat(dot)) ///
                   yline(14, lcolor(gray) lpat(dot)) ///
                   yline(20, lcolor(gray) lpat(dot)) ///
                   aspectratio(1.5) ///
                   scheme(cleanplots) legend(off) name("combined_v2", replace) ///
                   by(otype, rows(1) iscale(*.9) xrescale note("") legend(off))
            Last edited by Dirk Enzmann; 03 Apr 2025, 14:56.

            Comment


            • #7
              Thanks for the data example. Here is a way using twoway dropline to create the x-axis lines. For the subtitles, options can be specified within the option -subtitle()-. Changes are highlighted.


              Code:
              * Example generated by -dataex-. For more info, type help dataex
              clear
              input float otype long ncountrys double(b ll ul)
              1  1 1.8232662677764893 1.2744916677474976 2.6021058559417725
              1  2  2.354274272918701 1.8997215032577515  2.914358139038086
              1  4 1.9480551481246948 1.1691687107086182 3.2288742065429688
              1  5   1.18836510181427  .7556593418121338 1.8641927242279053
              1  6  2.804978847503662 1.9012080430984497  4.120327472686768
              1  7 2.5819835662841797 1.8128925561904907 3.6651699542999268
              1  9 1.6282821893692017 1.0509626865386963 2.5146775245666504
              1 10  2.465771436691284  1.726130723953247 3.5110225677490234
              1 11 1.0368071794509888  .5723732113838196 1.8709995746612549
              1 12  3.835354804992676   2.61684513092041  5.588690757751465
              1 13 2.7553815841674805  2.096219301223755 3.6141674518585205
              1 15  3.482848882675171 2.7548253536224365  4.394574165344238
              1 16 2.9384758472442627 1.9276129007339478   4.45536470413208
              1 17  4.120311260223389 3.2498581409454346  5.211350917816162
              1 18   4.69985818862915 3.8406169414520264  5.739858627319336
              1 19  3.604170799255371 3.1911513805389404  4.068399429321289
              1 21 3.0504472255706787  2.078294038772583  4.456643581390381
              1 22  3.702775239944458 2.9151315689086914  4.692945957183838
              1 23  3.055663824081421 2.2774438858032227  4.088681221008301
              1 24  4.522955894470215    3.7177894115448  5.492550849914551
              1 25 3.6960561275482178 2.9255692958831787  4.659719944000244
              2  1 2.2162022590637207 1.6103087663650513  3.043017864227295
              2  2 2.7415568828582764  2.247854471206665 3.3399875164031982
              2  4  2.276259660720825 1.4006472826004028 3.6788361072540283
              2  5 1.5470795631408691 1.0408555269241333 2.2938008308410645
              2  6  5.755327224731445 4.2833147048950195  7.692558765411377
              2  7 2.3652873039245605 1.6184827089309692 3.4446194171905518
              2  9  2.789125919342041 1.9968457221984863 3.8832998275756836
              2 10 2.5495307445526123 2.0424842834472656 3.1783673763275146
              2 11  2.524855136871338 1.6981732845306396 3.7386653423309326
              2 12 3.9136362075805664  2.763946294784546  5.514429569244385
              2 13 3.6556622982025146  2.891890525817871  4.611573219299316
              2 15 2.8116471767425537 2.1764423847198486   3.62536883354187
              2 16  6.897892475128174  5.288421630859375  8.950895309448242
              2 17  7.247931957244873   6.16160774230957  8.508415222167969
              2 18  4.250799655914307  3.443373918533325  5.237286567687988
              2 19  3.497159481048584 3.0947906970977783 3.9497101306915283
              2 21 3.3864657878875732  2.538670063018799  4.504300117492676
              2 22  5.779311180114746 4.7802252769470215  6.971920967102051
              2 23  6.591779708862305 5.4151811599731445  8.002397537231445
              2 24  6.519256114959717  5.550937175750732     7.642822265625
              2 25 11.913434982299805 10.545015335083008 13.432767868041992
              3  1 16.107105255126953 14.363504409790039 18.017831802368164
              3  2 11.198442459106445 10.162979125976563 12.324931144714355
              3  4 12.495499610900879 10.274386405944824  15.11587905883789
              3  5 10.005953788757324  8.606156349182129 11.604519844055176
              3  6 14.711297988891602 12.906121253967285 16.720491409301758
              3  7 13.343868255615234 11.521143913269043 15.404752731323242
              3  9 10.134563446044922  8.534324645996094 11.995504379272461
              3 10 13.752142906188965 11.857715606689453 15.894651412963867
              3 11  16.70213508605957   14.7279634475708   18.8823299407959
              3 12  18.36253547668457 15.617354393005371  21.46749496459961
              3 13 14.887200355529785 13.332172393798828 16.588886260986328
              3 15 18.207521438598633 16.500612258911133  20.04860496520996
              3 16  21.56774139404297 18.421165466308594 25.086511611938477
              3 17 20.616485595703125 18.789337158203125 22.571929931640625
              3 18 22.709247589111328 20.865633010864258  24.66498565673828
              3 19  24.63816261291504 23.667694091796875 25.635061264038086
              3 21 15.528800010681152 13.453604698181152 17.858041763305664
              3 22 18.792972564697266 17.010204315185547   20.7159481048584
              3 23 23.582414627075195 21.423551559448242  25.88715362548828
              3 24  22.67756462097168  20.90726661682129 24.551227569580078
              3 25 23.789976119995117  21.88181495666504 25.809558868408203
              end
              label values otype otype
              label def otype 1 "OType 1", modify
              label def otype 2 "OType 2", modify
              label def otype 3 "OType 3", modify
              label values ncountrys ncountrys
              label def ncountrys 1 "ncountry 01", modify
              label def ncountrys 2 "ncountry 02", modify
              label def ncountrys 4 "ncountry 03", modify
              label def ncountrys 5 "ncountry 04", modify
              label def ncountrys 6 "ncountry 05", modify
              label def ncountrys 7 "ncountry 06", modify
              label def ncountrys 9 "ncountry 07", modify
              label def ncountrys 10 "ncountry 08", modify
              label def ncountrys 11 "ncountry 09", modify
              label def ncountrys 12 "ncountry 10", modify
              label def ncountrys 13 "ncountry 11", modify
              label def ncountrys 15 "ncountry 12", modify
              label def ncountrys 16 "ncountry 13", modify
              label def ncountrys 17 "ncountry 14", modify
              label def ncountrys 18 "ncountry 15", modify
              label def ncountrys 19 "ncountry 16", modify
              label def ncountrys 21 "ncountry 17", modify
              label def ncountrys 22 "ncountry 18", modify
              label def ncountrys 23 "ncountry 19", modify
              label def ncountrys 24 "ncountry 20", modify
              label def ncountrys 25 "ncountry 21", modify
              
              scalar mean_otype_1 =  2.9152774810791
              scalar mean_otype_2 =  4.3403916358948
              scalar mean_otype_3 = 17.3048191070557
              
              gen double mean_otype= 2.9152774810791 if otype==1
              replace mean_otype= 4.3403916358948 if otype==2
              replace mean_otype= 17.3048191070557 if otype==3
              egen max = max(b)
              replace max= max+1.25
              
              
              
              
              twoway (rcap ll ul ncountrys, sort msize(medsmall) lcolor(maroon) hor) ///
                     (dot b ncountrys, sort fcolor(gs12) mcolor(navy) msymbol(circle) hor) ///
                     (dropline max mean_otype, base(-.025) lw(vthin) msymb(none) lc(black) lp(dash) vert), ///
                     ylabel(1(1)25, valuelabels labsize(8pt))  ///
                     yscale(reverse) xlabel(, grid glcolor(gs15) labsize(small)) ///
                      xtitle("% Last Year Prevalence {&plusmn} 95%-CI", size(6pt)) ///
                     yline(3, lcolor(gray) lpat(dot)) ///
                     yline(8, lcolor(gray) lpat(dot)) ///
                     yline(14, lcolor(gray) lpat(dot)) ///
                     yline(20, lcolor(gray) lpat(dot)) subtitle(, nobox) ///
                     aspectratio(1.5) ylab("") plotregion(margin(zero)) ///
                     scheme(stcolor) legend(off) name("combined_v2", replace) ///
                     by(otype, rows(1) iscale(*.9) xrescale note("") legend(off))

              Click image for larger version

Name:	Graph.png
Views:	1
Size:	98.8 KB
ID:	1775324



              Last edited by Andrew Musau; 03 Apr 2025, 15:29.

              Comment


              • #8
                Thanks a lot, that solves it!

                Comment

                Working...
                X