Announcement

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

  • label of x-axis

    Dear All, I was asked this question (https://bbs.pinggu.org/thread-10348633-1-1.html). The data set and code (to be modified) is:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(stock mon d)
    28 40 1
    23 35 2
    18 30 3
    25 36 4
    30 45 5
    end
    
    twoway connected stock d ||connected mon d,lp(dash) xscale(range(0.5 5.5))   ///
    xlabel( 1 "25岁以下"  2 "25-34"  3 "35-45"  4 "45-50"  5 "50岁以上" ) xtitle("") scheme(s1mono)
    The graph is
    Click image for larger version

Name:	1.png
Views:	1
Size:	57.3 KB
ID:	1588199

    But the desired one is (with relocation of the label on the x-axis):
    Click image for larger version

Name:	2.png
Views:	1
Size:	162.2 KB
ID:	1588200


    Please note particularly that the location of the x-axi, say 25-34. Thanks.
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    The x-axis is continuous, so in the same way that you can label "1" and "2", you can also label "1.5" and "13.3". Here is a way to achieve something similar to what is wanted.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(stock mon d)
    28 40 1
    23 35 2
    18 30 3
    25 36 4
    30 45 5
    end
    
    twoway connected stock d ||connected mon d,lp(dash) xscale(range(0.5 5.5))   ///
    xlabel( 1.5 "25岁以下"  2.5 "25-34"  3.5 "35-45"  4.5 "45-50"  5.5 "50岁以上", noticks ) xtick(#6, tposition(inside)) xtitle("") scheme(s1mono)
    You can explicitly specify the position of the ticks, but specifying the number of ticks ensures an even distribution across the axis.

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	18.4 KB
ID:	1588206

    Comment


    • #3
      Dear Andrew, Thanks again for your help. Is it possible to put the circles/squares just above the labels as the second graph I posted? Thanks.
      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment


      • #4
        The markers are in the integer positions, so you just want to modify the position of the inner ticks. [0.5(1)5.5] will do it.

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input double(stock mon d)
        28 40 1
        23 35 2
        18 30 3
        25 36 4
        30 45 5
        end
        
        twoway connected stock d ||connected mon d,lp(dash) xscale(range(0.5 5.5))   ///
        xlabel( 1 "25岁以下"  2 "25-34"  3 "35-45"  4 "45-50"  5 "50岁以上", noticks ) ///
        xtick(0.5(1)5.5, tposition(inside)) xtitle("") scheme(s1mono)
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	18.7 KB
ID:	1588292

        Comment


        • #5
          Dear Andrew, This is great. Thanks again.
          Ho-Chuan (River) Huang
          Stata 19.0, MP(4)

          Comment

          Working...
          X