Announcement

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

  • Formatting labels on graphs

    Hi,

    I have two questions about formatting labels on graphs, and I haven't been able to find answers to these questions either in the Stata help or online.

    First, if one of my axes has values >0 and <1, I would like to have "0" as the first label, and - say - "0.01" as the second label, etc. But if I do not impose any formatting, I get "0" and ".01" (would wish to have "0.01" instead). If I impose %9.2f, I get "0.00" and "0.01" (would wish to have "0" as the first label instead). Is there anything I can do about this?

    Second, the minus sign on my graphs looks very much like a hyphen, i.e. it's very short, much shorter than usual (I would expect it to be more like a dash). Is there anything I can do to make it less "hyphen-like" and more "dash-like"?

    I am very sorry if either of these questions is too simple or obvious.

    Best regards,

    Adam

  • #2
    Here's a silly graph but some technique. Set a format, but override it explicitly when you want something else.

    Code:
     
    sysuse auto
    
    scatter foreign mpg, yla(0 "0" 0.1(0.1)0.9 1 "1", ang(h) format(%03.2f))

    Comment


    • #3
      Click image for larger version

Name:	00.png
Views:	1
Size:	18.4 KB
ID:	1301601
      Adam, is this the kind of axis labeling you want?

      Comment


      • #4
        Nick, thank you very much -- this works perfectly for me!

        Sergiy, yes, this would be fine about "0" and "0.01"; however, I also needed some idea to solve my problem with the width of the minus sign. Using the format from Nick's reply, I've managed to solve this already!

        Thanks a lot to you both!

        Comment


        • #5
          Click image for larger version

Name:	0000.png
Views:	1
Size:	7.0 KB
ID:	1301610

          Same technique Nick and I were using to format the zero point can be applied to any other label. Above is an image with minus signs of different lengths interleaved.

          Comment


          • #6
            Originally posted by Sergiy Radyakin View Post
            Adam, is this the kind of axis labeling you want?
            Originally posted by Sergiy Radyakin View Post
            Above is an image with minus signs of different lengths interleaved.
            Sergiy, why so coy? Why won't you show your code? The graphs only demonstrate that something can be done in Stata but if you don't share how you did it the posts are less helpful than they could be otherwise.

            Comment


            • #7
              The challenge is really to understand the questions that are being posted.
              The code is no secret, as I mentioned, it is the same technique Nick has shown already. For the minuses it is:
              Code:
              sysuse auto, clear
              
              generate x=-weight/price/mpg
              summarize x
              twoway scatter price x, xlabel(-0.06 "`=char(151)'0.06" ///
                                             -0.05 "`=char(045)'0.05" ///
                                             -0.04 "`=char(151)'0.04" ///
                                             -0.03 "`=char(045)'0.03" ///
                                             -0.02 "`=char(151)'0.02" ///
                                             -0.01 "`=char(045)'0.01" ///
                                              0    "0", format(%03.2f))

              Comment

              Working...
              X