Announcement

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

  • Scale the axis in a histogram

    Hi,
    I am trying to scale the x-axis of a histogram, I tried scale, xscale and xscale(range(0 26)) for instance. It does not work.
    Do you have any idea?
    Many thanks

  • #2
    I cannot replicate that behaviour:

    Code:
    sysuse auto, clear
    
    // histogram without rescaling
    hist price, name(without)
    
    // histogram with rescaling
    hist price, xscale(range(0 20000)) name(rescaled)
    Can you give us more details; "does not work" isn't very informative.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      sure, sorry
      the type of the variable is float. I tried the hist command without rescaling

      hist age_car

      --> The x-axis ranged from 0 to 2000

      Then I applied your command

      hist age_of_the_car, xscale(range(0 26)) --> The x-axis still ranged from 0 to 2000 Is this enough information or do you need additional input? Kind regards

      Comment


      • #4
        Stata does not like it when you try and restrict the range of an axis to less than the range of the data; what do you mean by "scale the axis"? you can, after all, just divide the values of your variable by 100

        Comment


        • #5
          Originally posted by BurghauserBua View Post
          hist age_of_the_car, xscale(range(0 26)) --> The x-axis still ranged from 0 to 2000 Is this enough information or do you need additional input? Kind regards
          You may also consider having a look at this article, where this behaviour is neatly explained.
          Kind regards,
          Konrad
          Version: Stata/IC 13.1

          Comment


          • #6
            yes Rich Goldstein, thats the point. Even thoug I have large outlier with very high values, I only want stata to show me the x-axis up to a certain point (in my example 26), since the majority of the data are in this area...

            Comment


            • #7
              You'll then have to restrict the histogram adding an "if":
              Code:
              hist age_of_the_car if age_of_the_car<=26, xscale(range(0 26))
              Hope this helps!
              Carlos

              Comment


              • #8
                I am having the same trouble!!!! I don't want to use the 'if' statement since this affects the y axis! Any other ideas!?

                Comment


                • #9
                  barysaus: You asked this question in http://www.statalist.org/forums/foru...s-on-histogram and there was an answer.

                  Comment


                  • #10
                    Sorry Nick! I am new and did not realize you answered yesterday! Thanks

                    Comment

                    Working...
                    X