Announcement

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

  • how to suppress display of the interval from -1 to 1 of x-axis

    Here is the code:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double csw byte age
    -2.8 28
     3.2 28
     3.4 26
    -3.4 27
    -2.6 29
       4 26
    -3.4 27
     2.6 28
     3.2 25
       3 26
       3 25
    -3.6 26
     3.4 28
      -4 30
    -3.6 31
    -3.8 30
    -4.4 34
     3.4 33
       3 34
    -4.8 33
      -3 30
    -3.4 32
    -3.8 30
     3.6 34
    -3.6 33
    -3.8 30
     4.2 34
     3.8 33
    -3.6 32
     3.2 34
    -3.4 37
     2.6 35
     3.2 39
    -3.6 35
     4.6 39
     2.6 36
    -3.4 36
       3 36
      -3 37
    -2.8 37
     3.2 38
     3.8 35
     3.6 39
    -3.4 38
     4.4 39
    -4.2 38
     3.2 35
     3.6 38
    -4.2 37
     3.6 36
     3.4 39
     4.2 36
    -2.8 36
     3.8 36
    -3.2 39
      -3 36
    -3.6 39
    -3.8 37
    -3.2 35
    -3.6 37
     3.4 39
    -3.6 38
     3.8 42
    -3.2 40
    -2.8 40
     3.6 41
    -3.6 40
      -4 40
     3.4 42
    -3.4 44
      -4 40
    -3.6 42
    -3.6 44
    -3.6 44
    -3.4 40
    -3.6 41
    -3.4 44
    -3.8 40
    -3.6 44
    -3.6 44
    -3.2 42
       4 44
     4.2 40
    -3.6 40
    -3.6 42
    -3.6 43
       3 42
     3.2 42
    -3.4 44
     3.8 40
     3.2 43
     3.6 41
    -3.2 40
    -3.6 43
    -3.4 43
      -3 40
     3.4 47
     3.4 48
    -3.6 45
    -3.6 49
    end
    twoway dot csw  age ,hori ylabel(,nogrid) xlabel(-5 "5" -4 "4" -3 "3" -2 "2" -1 "1" 1(1)5)  xscale(r(-5(1)-1 1(1)5))
    Last edited by Fred Lee; 01 Apr 2019, 07:43.

  • #2
    https://www.stata.com/support/faqs/g.../scale-breaks/

    Comment


    • #3
      I thought Stata had easier way to realize this, It looks like a little complicated.

      Comment


      • #4
        In your case, you just need to move leftwards the points on the right hand side by 2 x-units. I do not see what is complicated about that.

        Code:
        gen CSW= cond(csw>1, csw-2, csw)
        twoway dot CSW  age ,hori ylabel(,nogrid) xlabel(-5 "5" -4 "4" -3 "3" -2 "2" 0 "2" 1 "3" 2 "4" 3 "5") xline(-1)
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	57.7 KB
ID:	1491193

        Comment


        • #5
          Originally posted by Andrew Musau View Post
          In your case, you just need to move leftwards the points on the right hand side by 2 x-units. I do not see what is complicated about that.
          Thanks a lot, It seems that I hadn't understood thoroughly. Thanks for your help.

          Comment


          • #6
            In fact some of the point of the FAQ -- at least on my part -- was to discourage scale breaks. What is csw here? Why are values close to 0 not observed? I have no idea whether it helps your purpose, but I played with transformed scales that shrink near zero and stretch higher values:

            Code:
            gen trans = sign(csw) * csw^2 
            * ssc inst mylabels 
            mylabels 5 4 3 2 1, myscale(-(@^2)) local(la1) 
            mylabels 5 4 3 2 1, myscale(@^2) local(la2) 
            twoway dot trans age ,hori ylabel(,nogrid) xlabel(`la1' 0 `la2')  xtitle(csw)
            Click image for larger version

Name:	age_csw.png
Views:	1
Size:	46.5 KB
ID:	1491220

            Comment


            • #7
              That's correct Nick, I did not read the FAQ. Here is an extension to #4 that would ensure no scale break. As stated in the FAQ, the requirement is that one needs integers to assign labels. Multiplying by 2 does the trick in this example.

              Code:
              gen CSW= 2*(cond(csw>1, csw-2, csw))
              twoway dot CSW  age ,hori ylabel(,nogrid) xlabel(-10 "5" -8 "4" -6 "3" -4 "2" -3 "1" -2"0" -1 "1" 0 "2" 2 "3" 4 "4" 6 "5") scheme(s1color)
              Click image for larger version

Name:	Graph.png
Views:	1
Size:	56.1 KB
ID:	1491228

              Comment


              • #8
                [QUOTE=Nick Cox;n1491219]In fact some of the point of the FAQ -- at least on my part -- was to discourage scale breaks. What is csw here? Why are values close to 0 not observed? I have no idea whether it helps your purpose, but I played with transformed scales that shrink near zero and stretch higher values:
                QUOTE]

                The values is obtained from a Likert-survey, ranging from 1 to 5, thus that is no need to display the value 0. Thanks.

                Comment


                • #9
                  So, now that makes sense. And #6 doesn't match that situation at all.

                  Presumably you have two groups you want to show back-to-back. Whether that's a good idea I've leave on one side, as I still need to know more about what is going on.

                  In that light Andrew Musau's #4 seems the best direction so far.

                  Thinking about it more

                  1. #1 shows that you want to show the limits 1 to 5 in each case.

                  2. There are overlaps -- two or more people with the same age and score. Jittering is a way to show that.

                  3. I have found grid lines with dots problematic as they don't port well into other software.

                  4. You'll surely want to explain your groups somehow.

                  Putting all that together, and repeating your data example for anyone's convenience, here is another try:

                  Code:
                  * Example generated by -dataex-. To install: ssc install dataex
                  clear
                  input double csw byte age
                  -2.8 28
                   3.2 28
                   3.4 26
                  -3.4 27
                  -2.6 29
                     4 26
                  -3.4 27
                   2.6 28
                   3.2 25
                     3 26
                     3 25
                  -3.6 26
                   3.4 28
                    -4 30
                  -3.6 31
                  -3.8 30
                  -4.4 34
                   3.4 33
                     3 34
                  -4.8 33
                    -3 30
                  -3.4 32
                  -3.8 30
                   3.6 34
                  -3.6 33
                  -3.8 30
                   4.2 34
                   3.8 33
                  -3.6 32
                   3.2 34
                  -3.4 37
                   2.6 35
                   3.2 39
                  -3.6 35
                   4.6 39
                   2.6 36
                  -3.4 36
                     3 36
                    -3 37
                  -2.8 37
                   3.2 38
                   3.8 35
                   3.6 39
                  -3.4 38
                   4.4 39
                  -4.2 38
                   3.2 35
                   3.6 38
                  -4.2 37
                   3.6 36
                   3.4 39
                   4.2 36
                  -2.8 36
                   3.8 36
                  -3.2 39
                    -3 36
                  -3.6 39
                  -3.8 37
                  -3.2 35
                  -3.6 37
                   3.4 39
                  -3.6 38
                   3.8 42
                  -3.2 40
                  -2.8 40
                   3.6 41
                  -3.6 40
                    -4 40
                   3.4 42
                  -3.4 44
                    -4 40
                  -3.6 42
                  -3.6 44
                  -3.6 44
                  -3.4 40
                  -3.6 41
                  -3.4 44
                  -3.8 40
                  -3.6 44
                  -3.6 44
                  -3.2 42
                     4 44
                   4.2 40
                  -3.6 40
                  -3.6 42
                  -3.6 43
                     3 42
                   3.2 42
                  -3.4 44
                   3.8 40
                   3.2 43
                   3.6 41
                  -3.2 40
                  -3.6 43
                  -3.4 43
                    -3 40
                   3.4 47
                   3.4 48
                  -3.6 45
                  -3.6 49
                  end
                  
                  gen CSW = cond(csw < 0, csw + 1, csw)
                  label def CSW -4 "5" -3 "4" -2 "3" -1 "2" 0 "1"
                  label val CSW CSW
                  label var CSW csw
                  set scheme s1color 
                  scatter  age CSW , ylabel(25(5)50, ang(h) nogrid) ysc(r(. 52))  ytic(25/50, grid) ///
                   ms(Oh) jitter(1)  xla(-4/5, valuelabel) xli(0.5) text(51.5 -2 "one group") text(51.5 3 "another group")
                  Click image for larger version

Name:	fred_lee_3.png
Views:	1
Size:	36.6 KB
ID:	1491265

                  Comment

                  Working...
                  X