Announcement

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

  • Change Histogram Axis labels for 2 values

    Hi !

    I want to create an histogram in Stata.

    I can do it but I also want to change the value "0" and "20" on the x axis by strings.
    i.e replace '0' with "start" and '20' with "End"

    Is there a way to put a string instead of a specific value ?

    Here is my code :

    HTML Code:
    #delimit;
    hist myhistogram, discrete
    percent
    xlabel(0(1)20,
    valuelabel
    angle(horizontal) labsize(small))
    xtitle("My Title");
    #delimit cr
    Here is a picture to illustrate :
    Click image for larger version

Name:	Sans titre.png
Views:	1
Size:	10.7 KB
ID:	1590206



    Thanks for your help

    Regards
    Lionel
    Last edited by Gurret Lionel; 19 Jan 2021, 06:50.

  • #2
    Code:
    xlab(0 "Start" 5(5)15 20 "End")

    Comment


    • #3
      Thanks Andrew, it's almost perfect !
      The only problem is that 0 and "Start" are one over the other
      Is there a way to remove the '0' and the '20' but only display "Start" and "End" ?
      Thanks

      Comment


      • #4
        #2 should do it. Present a data example if otherwise.

        Code:
        sysuse auto, clear
        hist trunk if trunk<=20, xlab(0 "Start" 5(5) 20 "End")
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	35.6 KB
ID:	1590212

        Comment


        • #5
          I am sorry I am kind of lost, I am new with Stata..

          I dont understand your comment about #2 :S

          Is this code correct ?

          HTML Code:
          sysuse auto, clear  
          #delimit;
          hist myhistogram, discrete
          percent
          xlabel(0(1)20, valuelabel angle(horizontal) labsize(small))
          hist trunk if trunk<=20, xlab(0 "Start" 5(5) 20 "End")
          xtitle("My Title");
          #delimit cr
          Thanks
          Last edited by Gurret Lionel; 19 Jan 2021, 07:25.

          Comment


          • #6
            I dont understand your comment about #2 :S
            My response in #2. You are mixing up my example with your code. -xlab()- and -xlabel()- refer to the same option, so you are supposed to modify this in your code.Try this:

            Code:
            #delimit;
            hist myhistogram, discrete
            percent
            xlab(0 "Start" 5(5) 20 "End",
            angle(horizontal) labsize(small))
            xtitle("My Title");
            #delimit cr
            Last edited by Andrew Musau; 19 Jan 2021, 07:33.

            Comment


            • #7
              Ok, thanks

              Almost perfect, it works for the 20 and "End"
              But still 0 and "Start" together.
              Can't find the difference and why it works with the 20

              Comment


              • #8
                Copy and paste the result of

                Code:
                dataex myhistogram

                Comment


                • #9
                  HTML Code:
                  [CODE]
                  * Example generated by -dataex-. To install: ssc install dataex
                  clear
                  input float myhistogram
                  2
                  2
                  3
                  0
                  5
                  2
                  1
                  1
                  0
                  2
                  1
                  7
                  6
                  0
                  2
                  0
                  5
                  7
                  1
                  6
                  4
                  2
                  3
                  1
                  1
                  1
                  0
                  0
                  2
                  3
                  0
                  1
                  1
                  1
                  0
                  0
                  4
                  4
                  0
                  2
                  4
                  0
                  4
                  3
                  2
                  0
                  0
                  2
                  0
                  0
                  0
                  2
                  2
                  7
                  2
                  2
                  0
                  4
                  1
                  5
                  2
                  2
                  .
                  5
                  7
                  1
                  1
                  5
                  5
                  0
                  0
                  1
                  4
                  1
                  0
                  1
                  0
                  4
                  .
                  0
                  2
                  0
                  5
                  2
                  3
                  4
                  1
                  4
                  2
                  8
                  0
                  2
                  1
                  1
                  0
                  .
                  1
                  1
                  4
                  2
                  end
                  label values myhistogram myhistogram_label
                  [/CODE]

                  Comment


                  • #10
                    The only way I reproduce your behavior is if I have two zeros specified within -xlab()-. Check that this is not the case. Otherwise, I cannot replicate this with the example data.

                    Code:
                    *REPLICATES
                    #delimit;
                    hist myhistogram, discrete
                    percent
                    xlab(0 0 "Start" 5(5) 20 "End",
                    angle(horizontal) labsize(small))
                    xtitle("My Title");
                    #delimit cr
                    Code:
                    *OK
                    #delimit;
                    hist myhistogram, discrete
                    percent
                    xlab(0 "Start" 5(5) 20 "End",
                    angle(horizontal) labsize(small))
                    xtitle("My Title");
                    #delimit cr

                    Comment


                    • #11
                      Thank you so much Andrew !
                      Take care !

                      Comment

                      Working...
                      X