Announcement

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

  • Zigzag or Squiggle in twoway line graph

    Dear all,

    I would like to add a zigzag or squiggle at my y-axis in my graph, but I don't know how to do this.
    I am graphing treatment adherence (in %) over time (in months). Currently my y-axis goes from 0 to 100%, but I would like to adjust it in order to improve the visibility of small differences.
    Hopefully it is possible to start my y-axis at 0%, then get a zigzag up to 60% (for example), and then continue until 100%, preferably with steps of 5%. Underneath I the code I currently use, I think the solution is somewhere in the ylabel part, but I'm not sure. I already made a graph where I replaced the ylabel(0(10)100) into ylabel(0 60(5)100), but then the distance between 0 and 60 remains big, while I would like to shorten it.

    Thanks in advance, Liza\ I use version 15

    Code:
    twoway (line percentage_ month, lcolor (black)), ///
    ylabel (0(10)100) xlabel (1(1)6) ///
    title("Ethiopia: TB treatment adherence over time", margin (medlarge)) ///
    ytitle("treatment adherence (%)", margin (medlarge) size(medsmall)) xtitle("time (month)", size(medsmall)) ///
    note("DAT used: 99DOTS, population: DS-TB patients", size(vsmall))
    Last edited by Liza de Groot; 20 Apr 2021, 05:56.

  • #2
    You can look at the following FAQ on scale breaks: https://www.stata.com/support/faqs/g.../scale-breaks/
    If this does not help you, present a data example showing your graph (or a similar graph), to better explain what is needed. If the variable is strictly positive, something as simple as a log scale may do the trick.

    Comment


    • #3
      Thank you Andrew for your quick response.
      I've already red the FAQ on scale breaks, but I cannot translate this to my situation. Since its all in percentages my dependent variable does not hold negatives, but I don't think that a log-transformation would increase the readability of the graph.
      This is what I have right now:
      Click image for larger version

Name:	Capture1.PNG
Views:	0
Size:	0
ID:	1604622



      I would like it to look more like this, but then with a stretched y-axis (but I don't know how to do this in paint):
      Click image for larger version

Name:	capture2.png
Views:	0
Size:	0
ID:	1604623

      Comment


      • #4
        Thank you Andrew for your quick response.
        I've already red the FAQ on scale breaks, but I cannot translate this to my situation. I dont have negative variables, but I don't think a log-transformation will improve the readability of my graph
        This is what I have right now:
        Click image for larger version

Name:	Capture1.PNG
Views:	2
Size:	58.4 KB
ID:	1604633

        And this is what I would like to have, but then with a stretched y-axis (in steps of 5%)

        Click image for larger version

Name:	capture2.png
Views:	1
Size:	30.7 KB
ID:	1604634
        Attached Files

        Comment


        • #5
          Scale breaks are usually an abomination. I am joint author of that FAQ but my not so hidden agenda was to discourage them for most purposes. (@Scott Merryman, who is active here, is entitled to a completely independent view.)

          Logit scale is often natural for plotting percentages 0 to 100 or proportions 0 and 1 so long as the extreme limits are not observed. https://journals.sagepub.com/doi/pdf...867X0800800113 says much more.

          For a case in which the limits are observed there are alternatives such as folded roots or other folded powers.

          If percents are mostly small and occasionally large logarithms often work well nevertheless. For small proportions, naturally logit y = log y - log (1 - y) ~ log y as log (1 - y) is near 0 when y is near 1.
          Last edited by Nick Cox; 20 Apr 2021, 08:04.

          Comment


          • #6
            #4 changes the picture. It seems that to me that the answer is just not to start the axis at 0.
            Last edited by Nick Cox; 20 Apr 2021, 08:15.

            Comment


            • #7
              Do you literally want a zigzag line on the axis? The way to do it would be to have the graph start at 59 and then to label it with a zero. You do not provide an example, but this illustrates a technique.

              Code:
              webuse grunfeld, clear
              twoway (line invest year if company==2, lcolor (black) ylab(0(100)700) ytitle("") scheme(s1color))
              Click image for larger version

Name:	Graph.png
Views:	1
Size:	50.7 KB
ID:	1604658



              Here, I restrict the y-range to 100 to 700 and label "100" with zero. If you shop around, you can get a zigzag character (perhaps from one of the Unicode characters), but I use a standard "Z" here.

              Code:
              webuse grunfeld, clear
              twoway (line invest year if company==2, lcolor (black) ylab(100 "0" 200(100)700) ysc(range(100, 700)) text(140 1934.6 "Z", size(huge) color(red)) scheme(s1color))
              Click image for larger version

Name:	Graph2.png
Views:	1
Size:	52.9 KB
ID:	1604659

              Last edited by Andrew Musau; 20 Apr 2021, 08:11.

              Comment


              • #8
                Dear Nick,
                Thanks for your response as well, I did get the discouraging message of the FAQ, which I do understand. I'm just looking for a way to get a better visual on the small difference, since even these small differences are highly clinical relevant.
                I'll take a look at the paper you've send, percentages of 96/97/98% are often observed, so I'll check whether using a logit scale would be feasible.

                Comment


                • #9
                  In your case my advice at #6 supersedes my advice at #5. In fact why not just plot non-adherence, which is the problem?

                  Comment


                  • #10
                    Thanks again, in your #6 advice I would make something like this

                    Code:
                    twoway (line percentage_ month, lcolor (black)), ///
                    ylabel (60(5)100) xlabel (1(1)6) ///
                    title("Ethiopia: TB treatment adherence over time", margin (medlarge)) ///
                    ytitle("treatment adherence (%)", margin (medlarge) size(medsmall)) xtitle("time (month)", size(medsmall)) ///
                    note("DAT used: 99DOTS, population: DS-TB patients", size(vsmall))
                    Which indeed gives what I want, although I was thinking it might be nice to show that the scale actually starts at 0, but that nobody has such low data.

                    To answer your question on the non-adherence option. It's data on tuberculosis treatment adherence a field in which "we" always speak about adherence, not non-adherence. All guidelines are focused on adherence (not non-adherence), if a treatment works at >=90% adherence, it would not be intuitive to write about treatment succes when non-adherence <10%/

                    But, thanks again! I'll just go with the "not starting at 0"

                    Comment


                    • #11
                      On starting at zero there was some discussion at https://stats.stackexchange.com/ques...-start-at-zero which seems close to my own views.

                      Comment

                      Working...
                      X