Announcement

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

  • graph dot axis not stretching properly

    I've seen this now with a bunch of different schemes--it seems to be better in some schemes than others, but it's bad in all of them I have tried (plotplain, 538w, and s2color, I don't like s2color but not everyone has plotplain).

    Code:
    sysuse bpwide, clear
    graph dot bp_before bp_after, over(agegrp) legend(pos(6) rows(1) label(1 "Before") label(2 "After")) scheme(s2color)
    graph export myfile.png, width(450) height(450)
    Gives me this:

    Click image for larger version

Name:	myfile.png
Views:	1
Size:	15.4 KB
ID:	1776551


    Okay, I get it, it is insisting the y axis start at 0. I planned to change the scale so it starts at 140 and ends at 180.

    Code:
    sysuse bpwide, clear
    graph dot bp_before bp_after, over(agegrp) legend(pos(6) rows(1) label(1 "Before") label(2 "After")) scheme(s2color) yscale(range(140(10)180))
    graph export myfile2.png, width(450) height(450)
    Click image for larger version

Name:	myfile2.png
Views:	1
Size:	15.5 KB
ID:	1776552


    Clearly something is preventing yscale from working properly, but it seems to happen no matter what scheme I use. I think I must have accidentally set something outside of the command. Is there something I am overlooking? (yaxis options also don't help)

    Thanks
    Jonathan

  • #2
    Answering my own question: use the option exclude0

    For some reason, I didn't need to do this on other graphs I've done, which is weird.

    Code:
    sysuse bpwide, clear
    graph dot bp_before bp_after, over(agegrp) legend(pos(6) rows(1) label(1 "Before") label(2 "After")) scheme(s2color) yscale(range(140(10)170)) ylabel(140(10)170) exclude0
    graph export myfile3.png, width(450) height(450) replace
    Click image for larger version

Name:	myfile3.png
Views:	1
Size:	15.8 KB
ID:	1776554

    Comment


    • #3
      I think dot chart is the same as bar chart in essence, and so it behaves like bar in drawing yvars from 0. (I checked helpfile and found that this is documented)
      Despite appearances, graph hbar and graph dot are in fact the same command, meaning that concepts and options are the same:
      And as to yscale, please note what Clyde Schechter have put it somewhere:
      Originally posted by Clyde Schechter View Post
      The -yscale()- option can only be used to expand the axis beyond the range of the data. It never produces a graph with an axis that is smaller than the full range of the y variable.

      Comment


      • #4
        In #2 the syntax

        Code:
        yscale(range(140(10)170))
        mixes the ayntax for scale and label options. Somehow that doesn't bite.

        Although I am generally positive about dot charts as implemented in graph dot, for precisely the problem of #1 they don't work very well in my view. The default choice of the same marker symbol can be overridden, but it's still hard work to link the legend and the body of the graph and even to see whether the direction of change is up or down in each case.

        https://journals.sagepub.com/doi/pdf...867X0900900408 is, or was, a fairly detailed discussion (https://journals.sagepub.com/doi/pdf...6867X241297949 adds some twists).

        Here is a different direction for the results graphed in #1. See help twoway for mentions of alternatives such as pccapsym and various arrow plots.

        Code:
        sysuse bpwide, clear
        gen before = 1
        gen after = 2
        egen mean_before = mean(bp_before), by(agegrp)
        egen mean_after = mean(bp_after), by(agegrp)
        twoway pcspike mean_before before mean_after after, ///
        by(agegrp, row(1) note("Age group", size(medium) pos(12))) ///
        xla(1 "Before" 2 "After") xtitle("") ytitle(Good text here) legend(off) ylabel(140(10)170)
        Click image for larger version

Name:	bp_age.jpg
Views:	1
Size:	50.8 KB
ID:	1776584

        Comment


        • #5
          I supposed Nick Cox's -linkplot- (from SSC) could do the work in #4, and I give a try by myself. (Certainly we can use bplong.dta directly.)
          Code:
          sysuse bpwide, clear
          egen bpBefore=mean(bp_before), by(agegrp)
          egen bpAfter=mean(bp_after), by(agegrp)
          reshape long bp, i(patient) j(j) string
          label define treat 1 Before 2 After, modify
          encode j, gen(treat) label(treat)
          linkplot treat bp if inlist(treat,1,2), link(agegrp) yla(1 2, valuelabel) asyvars cmissing(y) name(g1, replace)
          linkplot bp treat if inlist(treat,1,2), link(agegrp) xla(1 2, valuelabel) asyvars cmissing(y) name(g2, replace)
          Click image for larger version

Name:	g2.png
Views:	1
Size:	154.7 KB
ID:	1776684

          Comment


          • #6
            Chen Samulsion Thanks for the mention of linkplot (SSC) and for the reminder that the same data are in bplong.dta.

            That being so, it's easier to proceed from the long version and then we can use official commands directly.

            Code:
            sysuse bplong, clear
            egen mean = mean(bp), by(when agegrp)
            separate mean, by(agegrp) veryshortlabel
            line mean? when, xla(1 2, valuelabel) legend(off) aspect(1) ///
            || scatter mean when if when==2, ms(none) mlabsize(medium) mla(agegrp) mlabc(black) ///
            ytitle(Good text here) xsc(r(0.9 2.2))
            Many details are down to taste and circumstance but I note

            1. Agreement with Chen and indirectly with Jonathan Horowitz who started the thread that a single panel (graphical sense) works well.

            2. A personal preference for direct labelling rather than a legend whenever simpler. It can be arranged that the direct labels match each line in colour if that is desired.



            Click image for larger version

Name:	bplong_age.png
Views:	1
Size:	37.5 KB
ID:	1776693

            Comment


            • #7
              Dear Nick Cox, thank you for your reply. I saw you put direct labels at right end in many threads. https://www.statalist.org/forums/for...using-linkplot I must admit that it is very easily understand and nice looking. I wonder if Stata 20 or StataNow could add this as a new feature (say labelrightend?), just like they introduced colorvar option in Stata 18.

              Comment


              • #8
                But if the fictitious new feature is designed like colorvar, I would rather use the simpler
                Code:
                 || scatter, msymbol(none) mlabel(labelvar)

                Comment


                • #9
                  Naturally I am always happy that users get the means to do what they want (that makes sense) as easily as possible. Direct labels can be marker labels, added text, or even titles and it's both desirable and a complication that the position and rendering of direct labels may hinge on several desiderata. I think the available syntax is just fine myself.

                  Comment


                  • #10
                    A minor footnote to #6 and the neat labelling/legend formatting by Nick Cox. Note that the "veryshortlabel" option to -separate- is not mentioned in its help-file (versions 19.5 and 18 at least) but clearly it works. (See also -viewsource separate.ado-.)

                    Comment


                    • #11
                      Stephen Jenkins is clearly correct.

                      And thereby hangs a small tale. separate is an official command that grew out of some code I first wrote. After release I realised that the shortlabel option was often not enough as legend items such as foreign == Foreign were frequently longer than anyone needed or wanted (and ugly too; programmers know what == means but to many readers it probably looks like a typo), Hence for example Foreign would often suffice. So, I suggested an extra option which was a simple extension of the code, and the price paid was that it was not documented in the manual, as tweaking the code was then a much smaller deal than updating the manual (at a time, a multi-volume printed publication only).

                      However, it was mentioned in

                      SJ-5-4 gr0023 . . . . Stata tip 27: Classifying data points on scatter plots
                      . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
                      Q4/05 SJ 5(4):604--606 (no commands)
                      tips for using separate, gray-scale gradation, and text
                      characters as class symbols to classify data points on
                      a scatter plot

                      and many users have learned of the veryshortlabel option from that or perhaps even more often by just seeing examples of its use.

                      Comment

                      Working...
                      X