Announcement

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

  • Stata "insists" on setting x axis minimum at 0

    I plot yvar on xvar, with xvar's minimum at about 1100. stata "insists" on starting the x-axis at 0, even though there are no values of x below 1100.
    Trying to control the labels doesn't help. Any help would be greatly appreciated.

    Code:
    . summ x y
    
        Variable |        Obs        Mean    Std. Dev.       Min        Max
    -------------+---------------------------------------------------------
               x |        275    3879.695     2038.74       1101       7404
               y |        275    161.8545    123.1522         24        863
    
    twoway scatter y x, xlabel(1000(1000)7000)
    Attached Files
    Last edited by Ariel Karlinsky; 29 Apr 2017, 07:55.

  • #2
    Ariel: Perhaps try adding something like ... xscale(r(1000 8000)) to the scatter command.

    Comment


    • #3
      Doesn't help. Also, from looking at help files and discussions - it shouldn't help, as the scale command can only extend a given scale, never "shorten" it.

      Comment


      • #4
        Ariel: I made up some data where x ranged from 1000 to 8000 and used this command
        Code:
        scatter y x, xscale(r(1000 8000)) xlabel(1000 8000)
        It seemed to accomplish what you are looking for, unless I am misinterpreting.

        Comment


        • #5
          Actually for the data I generated the "xscale(...)" option doesn't even seem to be needed; "xlabel(...)" with or without xscale seems to do the trick. So the result in the graph you posted in #1 is now mysterious (to me). Insights beyond this are above my pay grade, alas.

          Comment


          • #6
            For what it's worth this was my code:

            Code:
            set obs 1000
            gen x=7*uniform()*1000+1000
            gen y=uniform()*1000
            scatter y x, xscale(r(1000 8000)) xlabel(1000 8000)
            And this was the result:
            Click image for larger version

Name:	Graphlist.png
Views:	1
Size:	194.5 KB
ID:	1386082

            Comment


            • #7
              Have you checked the variables using codebook? Or can you post an example using dataex that replicates the problem?

              Comment


              • #8
                I agree with Ariel's reading of the help information in post #3. However, I think the help information is misleading. I think the way to read the statement that a scale cannot be shortened is that actual data points will never be removed from the plot by the action of xscale(range(1000 8000)); however, the information is used, at least in certain circumstances by twoway scatter, to adjust its decisions about the axis scale. Now, why the code in #1 did not work while the code in #6 did is beyond my understanding.

                Comment


                • #9
                  John's example in #6 shows that this issue is not general, so unless you can post your data and specify which version of Stata you are using, there is not much else to say.

                  Comment


                  • #10
                    I'd add specification of scheme. It's worth checking out whether somehow your graph scheme isn't affecting settings.

                    Comment


                    • #11
                      Thanks Nick. I had also thought of this (my default is set to economist); I didn't try others, but at least scheme(sj) gave the same result.

                      Comment


                      • #12
                        There are a few attributes in the scheme files related to the scale of the axes. I don't remember their specific names off the top of my head, but think they were something along the lines of x_extend_scale yes. In either case, it would probably help if the OP provided a reproducible example that others could work from to try finding a viable solution.

                        Comment


                        • #13
                          It seems that the culprit is indeed my scheme, plottig by Daniel Bischof. The issue is replicated with Mullahy example data:
                          Code:
                          clear all
                          set seed 100
                          set obs 1000
                          gen x=7*uniform()*1000+1000
                          gen y=uniform()*1000
                          scatter y x, xscale(r(1000 8000)) xlabel(1000 8000)
                          Attached Files

                          Comment


                          • #14
                            Ariel Karlinsky ,

                            It looks like that scheme is trying to replicate the aesthetics of ggplot2. If that is the case and you want the same aesthetics, you can see an example of how to create a theme file with brewthemeand can use that to generate customized schemes with varying colors/shapes for your graphs with brewscheme. This would hopefully give you the aesthetics you want without the issues with the x-axis values.

                            Comment

                            Working...
                            X